View Single Post
This is a further update on the script, it launches OmniFocus if it wasn't running already and hides it from view (whether or not it was running). I got help from here. Ideally the script would leave OmniFocus at whatever window focus it was originally at (or hidden) and close it after if it was not already open. That will have to wait for another day though when I actually understand what to do and not just how to copy and paste :p.

I'm not sure why but it apparently helps telling OF to activate twice (according to the link). It's not as elegant as I would like but it gets the job done :).

tell application "System Events"
	set iSyncIsRunning to (count of (every process whose name is "iSync")) > 0
end tell

tell application "OmniFocus" to activate
tell application "OmniFocus" to activate
tell application "Finder"
	set visible of process "OmniFocus" to false
end tell

tell application "iSync"
	-- wait until sync status != 1 (synchronizing)
	repeat while (syncing is true)
	end repeat
	set syncStatus to sync status
	set lastSync to last sync
end tell

tell application "iCal"
	set theCalendars to every calendar
	repeat with theCalendar in theCalendars
		set theTodos to every todo in theCalendar
		repeat with theTodo in theTodos
			set theTodoSummary to summary of theTodo
			tell application "OmniFocus" to tell default document
				make new inbox task with properties {name:theTodoSummary}
			end tell
			delete theTodo
		end repeat
	end repeat
end tell

if syncStatus = 2 and not iSyncIsRunning then
	tell application "iSync" to quit
end if