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

Use cron to automate iSync at non-standard intervals Apps
I love the way Apple makes complex things simple. But being the lazy nerd that I am ... it can never be too easy. Up until recently, I've launched iSync from its menubar icon (you can set this inside the iSync preferences).

Now I have a cronjob that automatically launches iSync and tells it to synchronize me on both my iBook and my home iMac. It happens every two hours during work hours of three specific days of the week. Here's the cronjob I set with crontab -e on both machines:

0 8,10,12,14 * * 1,2,3 osascript -e 'tell application "iSync" to synchronize'
Translation: at 8am, 10am, 12pm and 2pm on Mondays, Tuesdays and Wednesdays, tell AppleScript to tell iSync to do its thing.
    •    
  • Currently 2.75 / 5
  You rated: 5 / 5 (4 votes cast)
 
[16,590 views]  

Use cron to automate iSync at non-standard intervals | 14 comments | Create New Account
Click here to return to the 'Use cron to automate iSync at non-standard intervals' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use cron to automate iSync at non-standard intervals
Authored by: FunkDaddy on Dec 09, '03 11:59:58AM

Good hint, I only want to sync every day or so.

Also, iSync has an option to sync automatically every hour in it's Preferences. Do you really need that extra hour?



[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: FunkDaddy on Dec 09, '03 12:01:22PM

OK, I'm an idiot... I'll read the post completely next time :)



[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: bseils on Dec 09, '03 12:49:33PM

For some reason that "every hour" doesn't work for me though.. I've got it clicked, but it doesn't actually sync.. <shrug>..



[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: encro on Dec 09, '03 01:50:53PM
Nice hint, sometimes I forget crontab is just begging to be used for things like this. I use a 7am daily sync instead:

#minute hour    mday    month   wday    who     command
0       7       *       *       *               osascript -e 'tell application "iSync" to syncronize'
Don't forget to set your EDITOR environment variable by adding the following line to your ~/.bash_profile on Panther:

# change pico to your preferred editor
export EDITOR=pico
... or your ~/.tcshrc on Jaguar:

# change pico to your preferred editor
setenv EDITOR pico


[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: hamarkus on Dec 09, '03 04:12:53PM

I do not seem to have the .tcshrc file on my Jaguar system (and yes I am looking for invisible files).
Any idea why?



[ Reply to This | # ]
.tcshrc
Authored by: sjk on Dec 09, '03 05:56:56PM

.tcshrc doesn't exist until you create it. See /usr/share/tcsh/examples/README for one way of doing it that also sets up a helpful (for some) tcsh configuration.



[ Reply to This | # ]
Nice for powerbook
Authored by: bignumbers on Dec 10, '03 09:45:15AM

Don't know why I didn't think of this... This is is a great solution for my powerbook. My desktop G5 syncs every hour per the prefs (more often than it needs to be, but doesn't bother me). I like to keep my powerbook sync'd but it's often out-and-about with me during the day so I just do it manually when I think about it.

I'll set this up to sync once or twice an evening, and life will be good.



[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: karlglazebrook on Dec 22, '03 12:20:25PM

Great. Been looking for that one for a while.

I notice iSync gets launched in the foreground.
What happens if there is a manual conflict to resolve?

Can one tell isync to synchronize in the background too? Like what happens when you tell it to sync from the menu bar thingy.



[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: mccu7pj2 on Jan 23, '04 02:08:14PM

And what happens if/when iSync prompts for your keychain password? Can this be automated?



[ Reply to This | # ]
An alternative method
Authored by: clarkcb on Jan 28, '05 08:32:56AM
This hint is great, but the following script has the added benefit of exiting iSync if it synchronizes successfully or displaying a dialog that describes the warning or error:

tell application "iSync"
  activate
  synchronize
  -- wait until sync status != 1 (synchronizing)
  repeat until sync status is not equal to 1
    1
  end repeat
  set syncStatus to sync status
  -- syncStatus = 2 -> successfully completed sync
  if syncStatus = 2 then
    quit
  else
    if syncStatus = 3 then
      set syncStatus to "completed with warnings"
    else if syncStatus = 4 then
      set syncStatus to "completed with errors"
    else if syncStatus = 5 then
      set syncStatus to "last sync cancelled"
    else if syncStatus = 6 then
      set syncStatus to "last sync failed to complete"
    else if syncStatus = 7 then
      set syncStatus to "never synced"
    end if
    display dialog "syncStatus: " & syncStatus
    syncStatus
  end if
end tell
I saved the script to my Scripts directory as iSync.scpt, and run it twice daily at noon and 8 pm using cron:
0 12,20 * * * osascript ~/Library/Scripts/iSync.scpt


[ Reply to This | # ]
Slight improvement
Authored by: TheWayOfTheGun on Apr 21, '05 05:52:29AM
Thanks for the tip. I'm installing that as a cron job. I did make two changes. First, I removed the activate call so that iSync can run in the background. Then, I noticed that the loop waiting for sync to finish is bound to burn a lot of CPU cycles. Here is a slight tweak that is a tad more efficient:

tell application "iSync"
	synchronize
end tell

on idle
	tell application "iSync"
		set syncStatus to sync status
		-- syncStatus = 2 -> successfully completed sync
		if syncStatus = 1 then
			return 7
		else if syncStatus = 2 then
			quit
			tell me to quit
		else
			if syncStatus = 3 then
				set syncStatus to "completed with warnings"
			else if syncStatus = 4 then
				set syncStatus to "completed with errors"
			else if syncStatus = 5 then
				set syncStatus to "last sync cancelled"
			else if syncStatus = 6 then
				set syncStatus to "last sync failed to complete"
			else if syncStatus = 7 then
				set syncStatus to "never synced"
			end if
			display dialog "syncStatus: " & syncStatus
			syncStatus
		end if
	end tell
end idle
To get this to work, you'll need to save as Application and check the "Stay Open" box. After the initial tell block, the idle block is called every few seconds. Once sync is done, the script tells iSync to quit and then quits itself.

[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: june on Aug 31, '05 05:52:50PM

This one works even beter

tell application "iSync"
activate
synchronize
repeat
if not syncing then exit repeat
end repeat
quit
end tell

return input
end run

---
The box siad; win 95 or better, so i bot a macintosch



[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: dfbills on Aug 16, '07 12:07:39PM

Any way to do this in Tiger? Without using iSync.app?

---
-d



[ Reply to This | # ]
Use cron to automate iSync at non-standard intervals
Authored by: lucidsystems on Jan 12, '12 02:03:37PM

Another update to the script from "TheWayOfTheGun".

This will only quit iSync after syncing if it was not running before the script is called.



set isync_status to do shell script "ps -A | grep -i /Applications/iSync | grep -v \"grep\" > /dev/null ; if [ $? != 0 ] ; then echo \"not running\" ; else echo \"running\" ; fi"
tell application "iSync"
activate
synchronize
repeat
if not syncing then exit repeat
end repeat
if isync_status is equal to "not running" then
quit
end if
end tell



[ Reply to This | # ]