Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ee99ee

macrumors 6502
Original poster
Mar 9, 2006
270
3
Is there a way I could setup iCal, or some appliaction, to automatically print my daily calendar at a certain time every morning? I'd like to wake up to a printed agenda for the day so I know what's going on...

Maybe an automator script that runs as a cron job? I've never used automator, so I'm just guessing...

-Chris
 
Is there a way I could setup iCal, or some appliaction, to automatically print my daily calendar at a certain time every morning? I'd like to wake up to a printed agenda for the day so I know what's going on...

Maybe an automator script that runs as a cron job? I've never used automator, so I'm just guessing...

-Chris

I think you could create a workflow in Automator that if run would print today's calendar.

To get it to run automatically, create a daily event in ical, and set an alarm for it. Two of the choices for the alarm are "open file" and "run script" one of these might be able to launch the automator workflow you created and thus print you calendar.
 
UI Script for printing daily calendar

Here is a UI script I used at one point to print my calendar each morning.

I hope it is what you are looking for.

Code:
tell application "iCal" to quit
delay 2
tell application "iCal"
	activate
	set frontmost to true
end tell
tell application "System Events"
	tell process "iCal"
		tell menu bar 1
			tell menu bar item "File"
				tell menu "File"
					click menu item "Print…"
				end tell
			end tell
		end tell
		delay 5
		tell window "Print"
			click pop up button 1
			click menu item "Day" of menu 1 of pop up button 1
			delay 1
			click pop up button 4
			click menu item "Today" of menu 1 of pop up button 4
			delay 1
			click button "Continue"
		end tell
		delay 1
		tell window "Print"
			click pop up button 3
			click menu item "### Change to Name of your Printer ###" of menu 1 of pop up button 3
			delay 1
			keystroke return
		end tell
	end tell
end tell

Just past that code into Applescript, input your printer name, schedule a task named something like "print schedule", and set the alarm to 'run script' and select this script.

Questions? Just ask.

-Ian
 
Request Help with This Script

Here is a UI script I used at one point to print my calendar each morning.

I hope it is what you are looking for.

Code:
tell application "iCal" to quit
delay 2
tell application "iCal"
	activate
	set frontmost to true
end tell
tell application "System Events"
	tell process "iCal"
		tell menu bar 1
			tell menu bar item "File"
				tell menu "File"
					click menu item "Print…"
				end tell
			end tell
		end tell
		delay 5
		tell window "Print"
			click pop up button 1
			click menu item "Day" of menu 1 of pop up button 1
			delay 1
			click pop up button 4
			click menu item "Today" of menu 1 of pop up button 4
			delay 1
			click button "Continue"
		end tell
		delay 1
		tell window "Print"
			click pop up button 3
			click menu item "### Change to Name of your Printer ###" of menu 1 of pop up button 3
			delay 1
			keystroke return
		end tell
	end tell
end tell

Just past that code into Applescript, input your printer name, schedule a task named something like "print schedule", and set the alarm to 'run script' and select this script.

Questions? Just ask.

-Ian

H! I am not experienced in compiling scripts. I tried to use yours and got the following:

"System Events got an error: Can’t get pop up button 3 of window "Print" of process "iCal". Invalid index."

Also, how do I do the following:

"schedule a task named something like "print schedule", and set the alarm to 'run script' and select this script."

As you can see, I am a complete novice! :-D
 
Well, it looks as though Leopard changed the Print dialog box. This new code should work, but it will simply use the default printer so make sure that is set properly.

Code:
tell application "iCal" to quit
delay 2
tell application "iCal"
	activate
	set frontmost to true
end tell
tell application "System Events"
	tell process "iCal"
		tell menu bar 1
			tell menu bar item "File"
				tell menu "File"
					click menu item "Print…"
				end tell
			end tell
		end tell
		delay 5
		tell window "Print"
			click pop up button 1
			click menu item "Day" of menu 1 of pop up button 1
			delay 1
			click pop up button 4
			click menu item "Today" of menu 1 of pop up button 4
			delay 1
			click button "Continue"
		end tell
		delay 1
		tell window "Print"
			keystroke return
		end tell
	end tell
end tell

To schedule this to run every morning, create an event in iCal at the time you want your schedule to be printed. Double click on the event and create an alarm that will "run script" and then select this script.

If you have any more questions, or if that doesn't work, let me know.
-Ian
 
20080222-eydjghte7ca7gruwhnnni9hnb2.jpg


Selecting "Run a script" as the action for an iCal event alarm.
 
I see open file as an option but not run script - please help



I think you could create a workflow in Automator that if run would print today's calendar.

To get it to run automatically, create a daily event in ical, and set an alarm for it. Two of the choices for the alarm are "open file" and "run script" one of these might be able to launch the automator workflow you created and thus print you calendar.
 
I would love to get this working. When I execute the script I get this error:

Result:
error "Calendar got an error: Can’t set frontmost of application to true." number -10006 from frontmost of application


I appreciate any help with this!
 
Code:
tell application "Calendar" to quit
delay 2
tell application "Calendar"
	activate
end tell
tell application "System Events"
	tell process "Calendar"
		tell menu bar 1
			tell menu bar item "File"
				tell menu "File"
					click menu item "Print…"
				end tell
			end tell
		end tell
		
		tell window "Print"
			click pop up button 1
			click menu item "Day" of menu 1 of pop up button 1
			
			click pop up button 4
			click menu item "Today" of menu 1 of pop up button 4
			
			click button "Continue"
		end tell
		
		tell window "Print"
			click pop up button 1
			click menu item "HP LaserJet 1015" of menu 1 of pop up button 1
			
			keystroke return
		end tell
	end tell
end tell
 
Hi, I have tried to adapt the previous code for macOS Big Sur, but the last part (clicking print) is still broken. Anyone that could spot what is wrong, how to fix it? The error is "error "System Events got an error: Can’t get button \"Print\" of window \"Print\" of process \"Calendar\"." number -1728 from button "Print" of window "Print" of process "Calendar"" and the code is below.
Code:
tell application "Calendar" to quit
delay 2
tell application "Calendar"
    activate
end tell
tell application "System Events"
    tell process "Calendar"
        tell menu bar 1
            tell menu bar item "File"
                tell menu "File"
                    click menu item "Print…"
                end tell
            end tell
        end tell
        
        tell window "Print"
            click pop up button 2
            click menu item "Day" of menu 1 of pop up button 2
            
            click pop up button 4
            click menu item "Today" of menu 1 of pop up button 4
            
            click button "Continue"
        end tell
        
        tell window "Print"
            click button "Print"
        end tell
    end tell
end tell
 
(shrug) Change the code to address the right GUI elements in Big Sur. GUI scripting is always brittle because menu elements move around, get renamed, etc.
 
In the end, I have found an app that shows exactly the UI hierarchy (called "UI browser" https://pfiddlesoft.com/uibrowser/) so I managed to find a way how to fix the error. For others, here is the functional script for macOS Big Sur:

Code:
tell application "Calendar" to quit
delay 1
tell application "Calendar"
    activate
end tell
tell application "System Events"
    tell process "Calendar"
        tell menu bar 1
            tell menu bar item "File"
                tell menu "File"
                    click menu item "Print…"
                end tell
            end tell
        end tell
       
        tell window "Print"
            click pop up button 2
            click menu item "Day" of menu 1 of pop up button 2
           
            click pop up button 4
            click menu item "Today" of menu 1 of pop up button 4
           
            click button "Continue"
        end tell
       
        tell window "Print"
            tell splitter group 1
                click button "Print"
            end tell
        end tell
    end tell
end tell`
 
  • Like
Reactions: doc james
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.