I recently installed the MacWorld Address Book Plugin that lets you Google an entry and it got me thinking: This is kind of cool, what else can I do with it?
There are some obvious ones, which is just applying the same parameter and just swapping out the URL (although I’m not sure what character the %22 stands for in the URL and Script). Here’s how they do it:
-- This script adds a menu to the phone number
-- to do a google search on the users name
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for thePerson with LastName
return "Google Them"
end action title
on should enable action for thePerson with Lname
return true
end should enable action
on perform action for thePerson with fone
set theURL to "http://www.google.com/search?q=%22" & name of thePerson & "%22"
tell application "Safari"
make new document
set URL of first document to theURL
activate
end tell
return true
end perform action
end using terms from
Now, while it’s fine to just do another web lookup (there are plenty of things you can do by passing the person’s name to a search engine or perhaps even their zip code to Mapquest, etc). But I started to get a little more ambitious and hit a wall.
I was thinking it might be handy to swap phone numbers. Here’s what I tried so far and no dice:
-- This script adds a menu to the phone number
-- to swap phone numbers 1 and 2, which I'm
-- assuming are the business and home phone numbers
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for thePerson with LastName
return "Swap Business and Home Phone Numbers"
end action title
on should enable action for thePerson with Lname
return true
end should enable action
on perform action for thePerson with fone
set ThephoneList to every phone of thePerson
copy item 1 of ThephoneList of thePerson to theBusinessPhone
copy item 2 of ThephoneList of thePerson to theHomePhone
set value of item 1 of phones of thePerson to theHomePhone
set value of item 2 of phones of thePerson to theBusinessPhone
return true
end perform action
end using terms from
The script currently does nothing. No error, and it compiles just fine. It looked like it should be pretty easy, but I’m missing something, I guess.
-D
It sure does, and it’s more robust (not depending on the person having #1 as business phone and #2 as home phone). I note that your swap method moves the labels rather than the data. Is this safer or just an easier way of doing it, since it now keys off the label rather than the data?
One could make versions of this to swap business and mobile numbers just by changing those parts of the code as well, and I’m guessing the swapping home and bussiness addresses shouldn’t be that much more (although there you have multiple pieces getting moved around).
Also on the ‘let’s try different Address Plugins’ subject
I also tried making an iCal appointment for today from a person, and that’s not quite there yet either - although the ‘cooler’ way to do this integration of Address Book and iCal would be to drag a person from the address book onto the target date. Right now you can drag a person into the Attendees slot (I didn’t know that until I just tried today!). Creating a new appointment with the current person as the title/attendee would be something like this:
using terms from application "Address Book"
on action property
return "phone"
end action property
on action title for p with e
return "Make Appointment with this Person"
end action title
on should enable action for pe with e
return true
end should enable action
on perform action for p with e
set theDate to today as string
set summary to p
tell application "iCal"
activate
set add to make new event at the end of events of (item 1 of (calendars whose title is calTitle)) with properties {start date:theDate, summary:theTitle}
end tell
end perform action
end using terms from
I know I’m close, but it’s not doing anything yet… Do I have the right idea?
The label is the only way to know which phone (or address) is which when using AppleScript (you’ve got some other options using Objective-C or C using the AddressBook.FrameWork. Incidentally, this is a better way of doing the number swap:
It’s cool the way you can include the person’s name in the menu.
Reminds me of those undo menus that actually tell you what you’re about to undo (particularly important in the case of multiple undos, where you want to get back to a particular point but no further and there’s little or no visual clue that you’ve reached that point).
I notice you are using properties here, which are saved in the script itself. What’s the advantage to using them here (aside from the tidiness of putting the main variables up front)?
The benefit of using properties is that the script can easily be localized for other languages simply by changing the properties (the labels are language specific).