I feel like this should be pretty easy, but I’m having trouble getting it implemented properly. Basically, I want Address Book to close if it isn’t the frontmost application (e.g. it’s not actively is use), and I want the computer to check every 60 seconds or so.
Why? Because I am using Snow Leopard Server, which does not allow several users to share an editable address book. The workaround is to have all the users sharing one account so that we can all access and modify the same address book. However, data integrity has been pretty poor since Address Book doesn’t seem to update the server properly, and it seems that ABs left open on other computers will erase the work done by someone else. I think the solution is to have ABs automatically close after a minute of being in the background so that as few ABs are open as possible. This way, only if someone is actively using it will the database be used.
So, I have this so far:
tell application “System Events”
if exists (some process whose name contains “Address Book”) then
set theAddressBookApp to some process whose name contains “Address Book”
else – Address book is not running
return
end if
if frontmost of theAddressBookApp is false then
tell application "Address Book" to quit
end if
end tell
I think that will work…but what’s the best way to set a timer? Should I use a cron job, or should I have applescript act as the timer?
Is there a better way to accomplish my goal?
Thanks,
Bhavesh