Skip to content

Instantly share code, notes, and snippets.

@aeppert
Created July 25, 2013 15:30
Show Gist options
  • Save aeppert/6080903 to your computer and use it in GitHub Desktop.
Save aeppert/6080903 to your computer and use it in GitHub Desktop.
#!/usr/bin/osascript
-- Author: David Koppstein
-- Version 1.0
-- A script for backing up named Calendars from iCal using the GUI interface. Currently,
-- it relies on the fact that exported calendars go to a default directory. Future versions,
-- if they ever come out, will hopefully take care of this issue. Furthermore, this program
-- also assumes that there is already a backed-up .ics file of the same name in that directory.
--
-- While the script is running, be sure not to click anything.
--
-- Use at your own risk, and enjoy!
-- Set myNames to the names of the Calendars you wish to backup
set myNames to {"WIBR Holidays", "Laura Resteghini's Bartel Lab Group Meetings"}
-- Optional shell script to run afterwards
set shellScript to "scp ~/Documents/Calendar_Backups/* koppology@koppology.webfactional.com:~/webapps/static_media/calendars; echo \"Successful backup at `date`\" >> ~/logs/calBackup.txt"
-- Begin script
tell application "iCal"
launch
activate
end tell
tell application "System Events"
tell process "iCal"
-- Refresh all the calendars
click menu item "Refresh All" of menu 1 of menu bar item "Calendar" of menu bar 1
delay 7
-- Left-hand menu of iCal, containing named calendars
set myOutline to outline 1 of scroll area 2 of window 1
set allRows to rows of myOutline
-- List of named calendars
set calNameVals to value of text field of every row in myOutline
-- For all named calendars, check whether it's the same name as one of myNames.
-- If so, export that calendar.
repeat with i from 1 to (count calNameVals)
set calName to item 1 of item i of calNameVals
repeat with myName in myNames
if (myName as string = calName as string) then
tell row i of outline 1 of scroll area 2 of window 1
select
end tell
click menu item "Export…" of menu 1 of menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1
click button "Export" of sheet 1 of window 1
click button "Replace" of sheet 1 of sheet 1 of window 1
end if
end repeat
end repeat
end tell
end tell
delay 3
tell application "iCal" to quit
-- Optional shell script for uploading to server
if shellScript is not "" then
do shell script shellScript
end if
-- End Script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment