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

Preserve 'my card' in Address Book after iSync over .mac Apps
I use iSync and .mac to maintain the same address book and iCal calendar on my wife's Cube and my PowerBook. Unfortunately, even under Panther, the "my card" entry also gets synchronized, so my wife becomes me and vice versa, depending upon who last changed an entry in the Address Book. This becomes annoying when, for example, iChat picks up the modified "my card" entry. Fortunately, the new Address Book in Panther lets you manipulate "my card" via AppleScript. So, it was a piece of cake to write the following scriptlet which restores "my card" after performing a sync.

try
  -- pick up current "my card"
  tell application "Address Book" to set CurrentMyCard to my card
    
  -- invoke a sync
  tell application "iSync" to synchronize
 
  -- wait for sync to finish
  repeat
    tell application "iSync"
      if (syncing is false) then
        exit repeat
        do shell script "sleep 15"
      end if
    end tell
  end repeat
  
  -- tell 'em who's the boss if iSync changed it 
  tell application "Address Book"
    set NewCurrentMyCard to my card
    if NewCurrentMyCard is not CurrentMyCard then
      set my card to CurrentMyCard
      save addressbook
    end if 
  end tell
end try
PS: I seem to recall that it used to be difficult to run AppleScripts from the crontab. I don't know if it is new in Panther, but I used the "save as a program" option in Script Editor 2.0, and placed a reference to it directly in my crontab for execution at 10 minutes to the hour:
50 * * * * /Users/myaccount/Scripts/sync_restore_my_card.app
And it worked as expected...
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[5,367 views]  

Preserve 'my card' in Address Book after iSync over .mac | 17 comments | Create New Account
Click here to return to the 'Preserve 'my card' in Address Book after iSync over .mac' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Understanding your AppleScript
Authored by: pwharff on Nov 19, '03 12:06:49PM

I'm trying to understand your script (I'm use to SHELL scripting and am new to AppleScript). Does this perform the sync for you also?



[ Reply to This | # ]
Understanding your AppleScript
Authored by: tedlandis on Nov 19, '03 02:01:35PM

If I may jump in, yes it does. So you would want to turn off the "Automatically synchronize every hour" setting in iSync preferences for .Mac

If you think about it, this avoids another issue with iSync by allowing you to schedule all syncs by different users to different set times. I sync the Address book on 3 machines with potentially 2 active users (by using fast user switching) for a total of 6 syncs per hour.

This functionality should be in Panther, but this workaround will do for now, thanks!

[ Reply to This | # ]
Since just about anyone w/ .Mac accts needs this...
Authored by: pairof9s on Nov 19, '03 02:26:59PM
...can you inform us newbies on how to place this in our crontab?

This is a godsend for my wife and I to use iCal/Address Book/Mail, if we can get it setup.

Thanks!!

[ Reply to This | # ]
Since just about anyone w/ .Mac accts needs this...
Authored by: paulrob on Nov 20, '03 03:33:51AM

Some articles here should get you going:
http://www.macdevcenter.com/pub/a/mac/2002/12/06/terminal_osx.html?page=1

WARNING: These articles cover Terminal app and Crontab in Jaguar. This does not guarantee that all examples will work in Panther - but the principles should be the same.



[ Reply to This | # ]
Since just about anyone w/ .Mac accts needs this...
Authored by: Graff on Nov 20, '03 04:06:41AM

Open Script Editor and paste in this code:

on idle
  try
    tell application "iSync" to set isSynching to syncing
    if isSynching is false then
      tell application "Address Book"
        set NewCurrentMyCard to my card
        if NewCurrentMyCard is not CurrentMyCard then
          set my card to CurrentMyCard
          save addressbook
        end if
      end tell
      if aBookRun is false then tell application "Address Book" to quit
      if iSyncRun is false then tell application "iSync" to quit
      quit
    end if
  end try
  return 1
end idle

on run
  try
    set abookRun to tell application "Finder" to ¬
      (name of processes) contains "Address Book"
    set iSyncRun to tell application "Finder" to ¬
      (name of processes) contains "iSync"
    tell application "Address Book" to set CurrentMyCard to my card
    tell application "iSync" to synchronize
    set isSynching to true
  end try
  idle
end run

Save the script using File -> Save As...

Select File Format -> Application and also select the checkbox "Stay Open"

Save it in /Applications/ (not ~/Applications/) as SyncScript

Download CronniX and install it.

Run CronniX. Click on the New button in the CronniX window.

Type in 50 for Minute and then click the first checkbox for the other options (Hour, Day of month, Month, Day of Week).

Type in "/Applications/SyncScript.app" for the command (do not type in the quotes)

Click New. The sheet should close. Click the Save button in the CronniX window. Quit CronniX. You should now be all set. The script will run at the 50th minute of every hour.



[ Reply to This | # ]
Since just about anyone w/ .Mac accts needs this...
Authored by: Graff on Nov 20, '03 04:10:16AM

One last thing, you need to do the CronniX setup for each account you want to run the script in. Just go in each account and repeat everything after the part about installing CronniX.



[ Reply to This | # ]
Since just about anyone w/ .Mac accts needs this...
Authored by: pairof9s on Nov 20, '03 05:45:09PM
I get an syntax error w/ the "tell" in this line:

set abookRun to tell application "Finder" to ¬

I would imagine it will happen in the iSyncRun line just below.

[ Reply to This | # ]
Since just about anyone w/ .Mac accts needs this...
Authored by: paulrob on Nov 21, '03 08:54:23AM

The line starting 'set abookRun to ... ' thru to ' .. contains "iSync"' 3 lines below should be replaced by: -

tell application "Finder"
set abookRun to (name of processes) contains "Address Book"
set iSyncRun to (name of processes) contains "iSync"
end tell



[ Reply to This | # ]
Since just about anyone w/ .Mac accts needs this...
Authored by: Graff on Nov 21, '03 12:45:14PM

Yeah, that way shortens the lines and produces basically the same script. I should have done that so that I could have avoided the line continuations which seem to cause so many headaches, but when you are doing stuff sometimes you just copy and paste and don't look to see if you should combine stuff.



[ Reply to This | # ]
Thanks everyone for the help!! *N/T*
Authored by: pairof9s on Nov 21, '03 01:10:45PM

n/t



[ Reply to This | # ]
Preserve 'my card' in Address Book after iSync over .mac
Authored by: webBarista on Nov 19, '03 03:46:01PM

This script is fantastic. This is the exact problem I was having between my Mac and my wife's laptop. I was within hours of removing Address Book syncing from from her laptop until I figured out how to script this on my own. Now I don't have too. Even seems to preserve the custom photos as they were set in the Accounts preferences.

As a matter of personal preference, I added a couple of lines to quit iSync and Address Book after they complete their respective tasks.

Just before "-- tell 'em who's the boss if iSync changed it" I added:

tell application "iSync" to quit

And right before the "end try" I added:

tell application "Address Book" to quit


[ Reply to This | # ]
Running AppleScript from crontab
Authored by: gxw on Nov 19, '03 07:43:38PM
PS: I seem to recall that it used to be difficult to run AppleScripts from the crontab.
No it isn't!
Answer == use osascript to call the applescript.
Sample crontab entry from my machine:
45 5 * * 1-5 osascript ~/wakeup
Osascript calls an AppleScript that starts iTunes playing @ 5:45 am monday thru friday. The ~/ is UNIX for my home directory or I could also have used
45 5 ** 1-5 osascript /Users/me/wakeup. NOTE: I have not tested this on Panther.....yet.

[ Reply to This | # ]
Preserve 'my card' in Address Book after iSync over .mac
Authored by: Graff on Nov 19, '03 11:46:43PM

One thing is that you are probably better off using an idle handler than a repeat loop and sleep combo. That's basically what the idle handler was created for in AppleScript. Here's your script converted over to using an idle handler:

on idle
  -- wait for sync to finish
  try
    tell application "iSync" to set isSynching to syncing
    if isSynching is false then
      -- tell 'em who's the boss if iSync changed it
      tell application "Address Book"
        set NewCurrentMyCard to my card
        if NewCurrentMyCard is not CurrentMyCard then
          set my card to CurrentMyCard
          save addressbook
        end if
      end tell
      quit
    end if
  end try
  return 1
end idle

on run
  try
    -- pick up current "my card"
    tell application "Address Book" to set CurrentMyCard to my card
    
    -- invoke a sync
    tell application "iSync" to synchronize
    set isSynching to true
  end try
  idle
end run


[ Reply to This | # ]
Preserve 'my card' in Address Book after iSync over .mac
Authored by: Christian Leue on Nov 20, '03 08:07:16AM

Yes, the "idle" event seems like the correct construction. But your sample code does not work for me. It triggers the event once at the beginning of the sync, "isSynching" remains true, and then never gets invoked again. Looks like I will read up on it...

Cheers,
Christian



[ Reply to This | # ]
Preserve 'my card' in Address Book after iSync over .mac
Authored by: Christian Leue on Nov 20, '03 08:32:06AM
Ok, the problem was just that I did not check the option "Do not quit automatically" when saving the script as an application. Also, it seems that it was necessary to declare the variables globally. So, to sum it up (and to include the good previous suggestion of terminating iSync when it's all over), this is the version I am using now:

global CurrentMyCard, isSynching

on idle
	try
		tell application "iSync" to set isSynching to syncing
		if isSynching is false then
			tell application "iSync" to quit
			tell application "Address Book"
				if my card is not CurrentMyCard then
					set my card to CurrentMyCard
					save addressbook
				end if
			end tell
			quit
		end if
	end try
	return 5
end idle

on run
	try
		tell application "Address Book" to set CurrentMyCard to my card
		set isSynching to true
		tell application "iSync" to synchronize
		idle
	end try
end run


[ Reply to This | # ]
Thanks everyone for the help!! *N/T*
Authored by: pairof9s on Nov 21, '03 01:08:21PM

n/t



[ Reply to This | # ]
Full strength script here!
Authored by: pairof9s on Nov 26, '03 07:49:36AM
After much work by Graf (another poster in this thread), the following script provides the ability to perform the My Card change in Address Book, sync w/ iSync, and then quit the applications. Set up the script to run via Cronnix and you now have an automatic means of performing the tasks.

Note: Be sure and save the script as an application and check the "Stay Open" option. Set Cronnix to run the script on the "Minute" you desire; set the others (Hour, Day, etc.) to the "Any" setting. Browse to your script's location and save.

global CurrentMyCard
global aBookRun
global iSyncRun
global isSynching

on idle
	try
		if isSynching is true then
			tell application "iSync" to set isSynching to syncing
			if isSynching is false then
				try
					tell application "Address Book"
						set NewCurrentMyCard to my card
						if NewCurrentMyCard is not CurrentMyCard then
							set my card to CurrentMyCard
							save addressbook
						end if
					end tell
				on error
					display dialog "An error occurred when attempting to set \"My Card\" in Address Book"
				end try
				try
					if aBookRun is false then tell application "Address Book" to quit
					if iSyncRun is false then tell application "iSync" to quit
					quit
				on error
					display dialog "An error occured when attempting to quit Address Book and iSync."
					quit
				end try
			end if
		end if
	on error
		display dialog "An Error occurred in the Idle Handler."
		quit
	end try
	return 1
end idle

on run
	try
		tell application "Finder"
			set aBookRun to (name of processes) contains "Address Book"
			set iSyncRun to (name of processes) contains "iSync"
		end tell
		tell application "Address Book" to set CurrentMyCard to my card
		tell application "iSync" to synchronize
		set isSynching to true
	on error
		display dialog "An Error occurred in the Run Handler."
		quit
	end try
	idle
end run


You can also download the script from my Homepage:
http://homepage.mac.com/pairof9s/FileSharing2.html

[ Reply to This | # ]