Hi,
Thought I'd have to do the way you suggest... I was hoping I had misread the dictionary for iCal and missed the export command! (Still a newbie at AS)
Cheers,
Nelson.
Absolutely - it's a little messy to have to rely on a variable file location in order to access the calendar as a file...
I'm ultimately trying to write a quick script which will upload via FTP a copy of the calendar to my webserver... (replacing my uses for .mac one step at a time!!!)
Nelson..
--path to ical calendar folders
set initial_path to ((path to home folder) & "Library:Application Support:iCal:Sources") as string
--get list of folders
set folder_list to {}
set folder_list to list folder initial_path without invisibles
--open each folder, checking each info.plist file for the name of the calendar I want
-- default calendar to be published is "Roster", but can be changed
set myCalendar to "Roster"
display dialog "Calendar " & "\"" & myCalendar & "\"" & " will be Published" buttons {"OK", "Change", "Quit"} default button "OK" with title "Calendar Publisher"
set button_pressed to button returned of result
if button_pressed is "Quit" then
return
else if button_pressed is "Change" then
tell application "iCal"
activate
set visible of window 1 to false
set all_calendars_names to the name of every calendar
choose from list all_calendars_names with prompt "Publish Which Calendar?" with title "Calendar Publisher"
if result is not false then
set myCalendar to item 1 of result
if myCalendar = "Birthdays" then
display dialog "Can't Publish The Birthdays Calendar" buttons {"Quit"}
return
end if
else
return
end if
end tell
end if
set num_chars to (count of items in myCalendar) as string
set x to ""
set found_folder to ""
repeat with x in folder_list
set theFile to initial_path & ":" & x & ":info.plist"
set file_contents to (read alias theFile)
set srch_string to characters 279 thru (279 + (num_chars - 1)) of file_contents as string
if srch_string contains myCalendar then
set found_folder to characters 206 thru 241 of file_contents as string
exit repeat
end if
end repeat
--set the full path to the wanted calendar
set theCalendar to initial_path & ":" & found_folder & ".calendar" & ":corestorage.ics" as string
--duplicate the file and rename it to the name of the Calendar
tell application "Finder" to (duplicate alias theCalendar to (path to desktop folder) with replacing)
set name of result to myCalendar & ".ics"
--upload to the ftp server
set pathtoapp to POSIX path of (path to application support from user domain)
set pathtodesk to POSIX path of (path to desktop)
set pathtosources to quoted form of (pathtoapp & "iCal/Sources")
set infolist to paragraphs of (do shell script "find -f " & pathtosources & "| grep -v “/Contents” | grep Info.plist$") -- produces a list of all the calendars that have a Info.plist file present
set calstartlist to {}
set caldestlist to {}
set calnamelist to {}
try
set desfolder to (do shell script "cd ~/Desktop ; mkdir Calendars") -- tries and make the Calendar folder at the desktop
end try
repeat with calname in infolist --repeats through the results of the above search
set calname to calname as string
set calname to text 1 thru -7 of calname
set calstart to quoted form of (text 1 thru -5 of calname & "corestorage.ics") --creates the path to the original .ics file
copy calname to end of calstartlist
set calname to quoted form of calname
try
set calname to (do shell script "defaults read " & calname & " Title") -- reads the INfo.plist file to grab the name of the calendar as set in iCal
set caldest to quoted form of (pathtodesk & "Calendars/" & calname & ".ics") --creates the destination path
copy calname to end of calnamelist
copy caldest to end of caldestlist
end try
end repeat
set calexport to choose from list calnamelist with multiple selections allowed
repeat with calname in infolist --repeats through the results of the above search
set calname to calname as string
set calname to text 1 thru -7 of calname
set calstart to quoted form of (text 1 thru -5 of calname & "corestorage.ics") --creates the path to the original .ics file
copy calname to end of calstartlist
set calname to quoted form of calname
try
set calname to (do shell script "defaults read " & calname & " Title") -- reads the INfo.plist file to grab the name of the calendar as set in iCal
set caldest to quoted form of (pathtodesk & "Calendars/" & calname & ".ics") --creates the destination path
if calname is in calexport then
do shell script "ditto " & calstart & " " & caldest --copies to the desktop while renaming it to the name given in iCal
end if
end try
end repeat
Thanks again!
I will "pull apart" your code and see if I understand what's going on.. truly appreciate the input!
Nelson.
How do I easily copy the code so I can paste it into Script Editor??
Of course that's how to do it!!
I would love to have a look at that code you wrote - thankyou.
Nelson..