AppleScript: Print daily iCal agenda
If you use iCal to store you important dates and events, and use it on a regular basis without syncing events via an iPod, iPhone, or other device, then you know how frustrating it can be when you forget about an appointment or event. I'm going to show you a way to automatically print your daily iCal agenda with a simple AppleScript. You can set this script to run when your Mac starts up so you never miss an appointment!Continue reading to learn how to create this AppleScript.
Creating the Script
Open Script Editor.app (it can be found in /Applications/AppleScript). When you have the application opened, type (or copy / paste) the entire AppleScript below.
tell application "iCal"
view calendar at (my (current date))
switch view to day view
activate
tell application "System Events"
keystroke "p" using command down
delay 1 -- (seconds)
keystroke return
delay 2 -- (seconds)
keystroke return
end tell
quit
end tell
When you are finished, your script should look similar to the one below.

Saving the script
You can save this script as an application by clicking File > Save As, and choosing "Application" from the "File Format" drop-down box. Type a name and location for your script to be saved and then click the "Save" button.

Running the script
To run this script, you can double-click on the application that you just created or you can drag it into the dock for easy clicking (or right-click on the icon in the dock and select "Open at Login" to have your script run when you login to your account).
When the script runs, it will open iCal, set the view to the current date, and will then print the current view. Normally, this would take a couple minutes to do by hand, but you can now have an iCal agenda quickly printed off.
Additional notes
- This script assumes that you are using either Mac OS X "Tiger" (version 10.4) or "Leopard" (version 10.5). I have yet to test this on 10.3 or below, but it may work on older versions of Mac OS X.
- In order to use this script, you must enable "GUI Scripting." To do this, open "AppleScript Utility" in the /Applications/AppleScript directory. Then check the "Enable GUI Scripting" checkbox.
Share
Source: http://tuaw.com/tag/AppleScript
var digg_url = 'http://digg.com/apple/TUAW_Use_an_AppleScript_to_have_iCal_deliver_a_daily_agenda'; If you use iCal to store you...
Add a Comment
Tried it out and it works like a charm.
the "print" option in iCal gives me the same page, so is the advantae that I can have this spript print the daily list automatically, or am I missing somehting?
I have done similar with a different script I found in one of the Apple tips message boards (then I set an event with an alarm to run it on weekdays.)
I have tried to modify it to do a couple of things, and that's where I'm running into difficulty:
1. I want it to uncheck a calendar (I created one called "invisible" so these events don't show up as part of the day's activities.) -- I can't figure out how to tell Applescript how to go into the subwindow that the list of calendars is in.)
2. I want to make sure it always selects the correct printer, but when I tell it to "click pop up button 1," it selects the print settings pulldown, instead of the printer list pulldown above it. (So right now, I just set the inkjet as the default printer, and it usually goes to the right place.)
It really seems silly that iCal is not recordable ... for novices like me it is a great option, because I can run something just to find out how the API names the buttons/pulldowns/pop ups etc.
Never posted a script so i hope this comes out right. Anyway this would print out the day view as a pdf in the folder ical prints its pdfs and saves its backups.
You could then add a folder action to that specific folder to look for pdf´s created today and add that pdf as an attachment to an outgoing mail to the email address of your choice
set todaysDate to (current date)
set {d, m, y} to {day, month, year} of todaysDate
set yearString to text -2 thru -1 of ("0" & (y mod 100))
set monthList to {January, February, March, April, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if m = (item i of monthList) then
set monthString to text -2 thru -1 of ("0" & i)
exit repeat
end if
end repeat
set todaysDate to " - " & d & "/" & monthString & "/" & yearString
tell application "iCal" to activate
tell application "System Events"
tell process "iCal"
keystroke "t" using command down
keystroke "p" using command down
delay 3
keystroke return
delay 5
delay 5
click menu button "PDF" of window "Print"
perform action "AXPress" of menu item "Save as PDFâ¦" of menu 1 of menu button "PDF" of window "Print"
delay 2
keystroke "iCal" & todaysDate
keystroke tab
keystroke return
keystroke return
end tell
end tell
I had written something very similar to that a month ago. However, no matter what I did, whenever I got to the part where the script was looking to access the Print PDF menu, it crapped out and gave me the NS-4 error (or whatever it is). Just tested yours (in Tiger) and got the same. Which is why I went the Automator way. It still summarizes to email, but not near as nicely as the PDF.
April 30 2008 at 9:12 AM Report abuse Permalink rate up rate down Reply@justin - the only problem is that your method does not find recurring events (and I have yet to fond any method that does).
April 28 2008 at 10:54 PM Report abuse Permalink rate up rate down Replylove it!
keep the applescript tips coming!
"You can set this script to run when your Mac starts up" -- you shut down your Mac?
April 28 2008 at 2:42 PM Report abuse Permalink rate up rate down Reply@geddy76 - unfortunately, 10.5's iCal Automator 'Event Summary' action differs significantly from 10.4 Tiger's. And I have not (yet) found an easy way to find recurring events whose recurrence = today.
Still working on it.
I confirm, the automator version does not work in Leopard.
This is why I have been looking for an Applescript version...
the way to do this in leopard is:
Get specified iCal items, and select the calendar you want.
Filter events in iCal whose start date is today.
Event summary so you get all the details of the events.
New Mail message with what you want.
Send outgoing messages.
jt
Actually, you could take this a step further and create a reoccurring task in iCal that would kick off early in the morning (say 5 or 6 am) and run this applescript - printing your agenda.
Then as you run out the door for the day, you have a printed agenda waiting for you!
Very nice, indeed.
Now let's take it up a notch. Show us how to replace the block with a way to email the day's events to a particular email address.
Thanks!
Hot Apps on TUAW
Deals of the Day
more deals- Altec Lansing Octiv Duo iDock for $48 + free shipping
- Used Apple iMac 17" Core 2 Duo 1.83GHz for $430 + $28 s&h
- Lounge Deluxe Stand for iPhone / iPod touch for $28 + $8 s&h
- Brookstone Surround-Sound Earbuds for $14 + $7 s&h
- Refurbished Skullcandy Tokidoki Smokin' Buds Mic'd Headset for $5 + $2 s&h
- Stitchway Backup Battery for iPod / iPhone for $5 + free shipping
Software Updates
more updates- EFI Firmware Update brings Lion Internet Recovery to 2010-model Macs
- OS X Lion 10.7.3 released with Safari 5.1.3, Wi-Fi bug fix
- Aperture updated to 3.2.2, addresses Photo Stream issue
- Apple updates Keynote to address Lion issues
- Google Search app gets new look on iPad
- Apple releases Apple TV Software Update 4.4.3



15 Comments