Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Edit and sync iCal calendars on multiple machines' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Edit and sync iCal calendars on multiple machines
Authored by: ptone on Oct 24, '05 09:02:00AM
This is a 'first draft' applescript app that lets you do this without having to lookup the corestorage.ics file. -Preston

property icalSupportFolder : (path to home folder as string) & "Library:Application Support:iCal:"
property nodesPlist : icalSupportFolder & "nodes.plist"
property sources : {}
property passwds : {}

on getValue(akey, keys, values)
	if keys does not contain akey then return false
	repeat with i from 1 to count of keys
		if item i of keys = akey then return item i of values
	end repeat
	return false
end getValue

on getPW(source)
	log "PW routine"
	return my getValue(source, sources, passwds)
end getPW

--iCal should be closed to refresh
tell application "Finder"
	if name of every process contains "iCal" then
		tell application "iCal" to quit
	end if
end tell

tell application "System Events"
	--set nodesPlist to POSIX path of nodesPlist
	set calendarList to property list items of property list item "List" of contents of property list file nodesPlist
	set publishedCalendarList to {}
	--set publishedCalendarNames to {}
	repeat with i from 1 to count of calendarList
		set pubData to property list items of property list item "Publishers" of item i of calendarList
		if pubData ≠ {} then
			--set end of publishedCalendarList to i
			set end of publishedCalendarList to ((i as string) & " : " & value of property list item "PublishName" of item 1 of pubData)
		end if
	end repeat
	
	set chosenCalendars to choose from list publishedCalendarList with prompt "Choose calendars to refresh (hold CMD key for multiple)" with title "Published Calendars" with multiple selections allowed
	repeat with aChosenCalendar in chosenCalendars
		set calIndex to characters 1 thru 2 of aChosenCalendar as string as number
		set sourceItem to value of ¬
			property list item 1 of ¬
			property list item "Sources" of ¬
			property list item 1 of ¬
			property list item "Publishers" of (item calIndex of calendarList)
		set sourceURL to value of ¬
			property list item "UploadURL" of ¬
			property list item 1 of ¬
			property list item "Publishers" of (item calIndex of calendarList)
		
		set sourceFile to icalSupportFolder & "Sources:" & sourceItem & ".calendar:corestorage.ics" as alias
		
		
		(* --- URL Access scripting does not store pw in keychain
		tell application "URL Access Scripting"
			download sourceURL to sourceFile replacing yes with authentication
		end tell
		*)
		
		--using curl for download and storing pw
		if sourceURL contains "@" then --authentication steps
			set username to characters 8 thru ((offset of "@" in sourceURL) - 1) of sourceURL as string
			
			if sources contains sourceItem then
				set passwd to my getPW(sourceItem)
			else
				display dialog "Please enter your password" with title "Web Authentication" default answer "" buttons {"OK, Always", "OK, Once"} default button 1 with hidden answer
				set theResult to result
				set passwd to text returned of theResult
				if button returned of theResult = "OK, Always" then
					set end of sources to sourceItem
					set end of passwds to passwd
					
				end if
			end if
			set sourceFile to POSIX path of sourceFile
			set sourceFile to quoted form of sourceFile
			set userpass to username & ":" & passwd
			set sourceURL to "http://" & characters ((offset of "@" in sourceURL) + 1) thru -1 of sourceURL as string
			set shellcommand to "curl -u " & userpass & " " & sourceURL & " -o " & sourceFile
			do shell script shellcommand
		else
			--no auth needed
		end if
		
		
	end repeat
	tell application "iCal"
		reload calendars
		activate
	end tell
	
end tell


[ Reply to This | # ]
Edit and sync iCal calendars on multiple machines
Authored by: vman on Jan 14, '07 01:58:31PM
thanks, after some hassling setting things up this script works great.

for anyone who might be trying to do the same:
I'm running phpicalendar on my server, and publishing my calendars in iCal.app to the [www.mysite.com]/phpicalendar/calendars/ directory, as described in the publish.ical.php file in that location. (for use with the above applescript be sure to publish to the /calendars/ directory and not /calendars/publish.php , this does not work)
next I've modified the applescript somewhat to bypass the 'choose which calendar'& password dialogs, made it into an application, and put it in the dock instead of iCal.app.
This way when I open iCal now it does a sync/download first from the server.


On this subject,
it would be a better solution if we had something like this that would check the modification dates first before upping/downloading anything.. or come to think of it actually check individual event changes within the .ics files... hmm.
ah well, maybe things get better in osx 10.5.

cheers

[ Reply to This | # ]