View Full Version : Hint: Automatically sync with iCal every hour
Schimmi
09-25-2007, 02:37 AM
Just a small hint to automatically sync with iCal, iSync and OmniFocus:
Start the Terminal
Enter "crontab -e"
The editor VI is started. Press "i" to enter insertion mode.
Paste the following to iSync every hour with the configured device: 27 * * * * osascript -e 'tell application "iSync" to synchronize'
Paste the following to sync OmniFocus with iCal a few minutes later: 33 * * * * osascript -e 'tell application "System Events" to click button "Sync with iCal" of tool bar 1 of window "OmniFocus" of process "OmniFocus"'
Make sure that the iCal sync button is in your OmniFocus toolbar!
Press the Escape key and type :wq and finish with the enter key to quit the VI editor.
That's it: iCal will sync with your mobile every hour at 27 minutes, OmniFocus will sync with iCal every hour 6 minutes later.
Some more information about the editor VI: http://en.wikipedia.org/wiki/Vi
This would be very helpful, but how do you get the iCal sync onto the Omnifocus toolbar?
View Menu -> Customize Toolbar
Drag the "Sync with iCal" button.
Schimmi
10-16-2007, 12:53 AM
Here is a more advanced shell script to sync. It basically iSyncs twice around one sync of OmniFocus to get every task from and to your mobile device. You can easily adapt it to your needs:
#!/bin/sh
# quit iSync (because somehow it is more reliable with my mobile with a fresh iSync)
osascript -e 'tell application "iSync" to quit'
sleep 5
# sync and wait
osascript -e 'tell application "iSync" to synchronize'
while [ `osascript -e 'tell application "iSync" to syncing'` = "true" ]; do
sleep 1
done
# sync OmniFocus
osascript -e 'tell application "System Events" to click button "Sync with iCal" of first tool bar of first window of process "OmniFocus"'
sleep 15
# sync iSync again
osascript -e 'tell application "iSync" to synchronize'
while [ `osascript -e 'tell application "iSync" to syncing'` = "true" ]; do
sleep 1
done
# quit iSync
osascript -e 'tell application "iSync" to quit'
Stefan
CosmicVoyager
12-19-2007, 10:42 AM
The script doesn't work for me. I get:
36:124: execution error: System Events got an error: Can’t get window "OmniFocus" of process "OmniFocus". (-1728)
Being relatively new to Macs (but loving it!), I don't really want to go poking around too much in terminal. Is the script still valid for the latest builds? It would be great if there was an "automatically sync every x minutes" in the preferences.
Thanks for any help.
Schimmi
12-20-2007, 12:22 AM
It seems to be broken. Will take a look... Thanks for pointing that out!
Stefan
Schimmi
12-20-2007, 01:13 AM
In fact it's much easier now:
tell application "OmniFocus" to ical_synchronize first document
Hence the cron entry will be:
33 * * * * osascript -e 'tell application "OmniFocus" to ical_synchronize first document'
And the whole script:
#!/bin/sh
# quit iSync
osascript -e 'tell application "iSync" to quit' > /dev/null
sleep 5
# sync and wait
osascript -e 'tell application "iSync" to synchronize' > /dev/null
sleep 3
while [ `osascript -e 'tell application "iSync" to syncing'` = "true" ]; do
sleep 1
done
# sync OmniFocus
osascript -e 'tell application "OmniFocus" to ical_synchronize first document'
sleep 15
# sync iSync again
osascript -e 'tell application "iSync" to synchronize' > /dev/null
sleep 3
while [ `osascript -e 'tell application "iSync" to syncing'` = "true" ]; do
sleep 1
done
# quit iSync
osascript -e 'tell application "iSync" to quit' > /dev/null
Netzach
12-20-2007, 03:25 AM
So, correct me if I'm wrong, if I only want to sync OmniFocus with iCal every 15 minutes, all I put in the crontab is:
1 * * * * osascript -e 'tell front document of application "OmniFocus" to ical_synchronize'
16 * * * * osascript -e 'tell front document of application "OmniFocus" to ical_synchronize'
31 * * * * osascript -e 'tell front document of application "OmniFocus" to ical_synchronize'
46 * * * * osascript -e 'tell front document of application "OmniFocus" to ical_synchronize'
And that's all?
CosmicVoyager
12-20-2007, 08:37 AM
Yes, that did the job. Thanks, Schimmi!
NETZACH: Use "1,16,31,46" (without the quotes) as the first parameter and combine your four lines into one.
aultc
01-12-2008, 10:12 AM
The latest version of this script looks like exactly what I need, but I'm new to this and therefore a little unclear where the all the pieces go. I enter the cron info in the VI editor, but where do I enter (and save?) the "whole script" ?
Thank you!
lucidr
02-16-2008, 03:28 AM
It would probably be better to use launchd for this these days as cron is more or less deprecated on OS X. launchd is much better anyway, and you can use Lingon (http://lingon.sourceforge.net/) to edit your entries - its pretty much self explanatory. And you have the option of using clever triggers like file modification.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.