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

A Google personal lookup plug-in for Address Book Apps
After reading through several applescript based plug ins for the address book I decided to try some of my own and thought I would share this one. It attaches a "Google Me" option to the phone number of an individual, and does a google search on their name.

To use this, open Script Editor (in Applications -> AppleScript), copy the text of the script in, and save it with a fitting name ("GoogleThem") in the "Library -> Address Book Plug-Ins" folder under your home directory. Save it with a File Format of "Script."
 -- 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 Me"
  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=" & name of thePerson
    
    tell application "Safari"
      if (count of documents) is 0 then
        make new document
      end if
      set URL of first document to theURL
      activate
    end tell
    return true
    
  end perform action
end using terms from
To use it, launch AddressBook, select an individual, and then control-click on their phone number and select GoogleThem (or whatever you named the script).
    •    
  • Currently 2.00 / 5
  You rated: 2 / 5 (3 votes cast)
 
[8,615 views]  

A Google personal lookup plug-in for Address Book | 9 comments | Create New Account
Click here to return to the 'A Google personal lookup plug-in for Address Book' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A Google personal lookup plug-in for Address Book
Authored by: maxsnet on Dec 16, '04 06:37:06PM

as a user of Camino, i just changed the script to use Camino, this way :

tell application "Camino"
open location theURL
activate
end tell
return true

enjoy,
max



[ Reply to This | # ]
A Google personal lookup plug-in for Address Book
Authored by: felddy on Dec 17, '04 12:54:28AM
The open location command is part of the standard additions. Just leave the command outside all tell blocks and the URL open event will be sent to the default browser. (Which is set in Safari's preferences).

[ Reply to This | # ]
Re: "open location"
Authored by: nicksay on Dec 18, '04 07:10:24PM
I could not get the open location command to work on its own. I tried both calling it directly (without any tell blocks) and putting it in a separate function and passing the url to that function — neither worked. What did work, however, was to tell System Events to open the url:
tell application "System Events" to open location theURL
Because the open location command usually works without any tell blocks, I figure one explanation might be that Address Boook is intercepting the command.

[ Reply to This | # ]
A Google personal lookup plug-in for Address Book
Authored by: sdickers@mac.com on Dec 17, '04 09:57:18AM

Dear davegolden,

It works great. I have found that it works better if a middle name is included.

Is there a way to get AppleScript to put quotes around the entire name? It would reduce the number of entries down to only the relevant ones in most cases. I have no experience with AppleScript other than copying other peoples' codes character per character. I need to learn how to write my own scripts.

Thank you.

Sincerely,
Steve Dickerson



[ Reply to This | # ]
A Google personal lookup plug-in for Address Book
Authored by: maxsnet on Dec 17, '04 10:54:55AM

is that you need ?

set theURL to "http://www.google.com/search?q=\"" & name of thePerson & "\""



[ Reply to This | # ]
A Google personal lookup plug-in for Address Book
Authored by: bkazez on Dec 18, '04 10:48:54AM

Actually, it's considered better form to %-encode characters in URLs. I'd recommend replacing the \" items with %22.

Ben

---
http://ben.kazez.com/

[ Reply to This | # ]

A Google personal lookup plug-in for Address Book
Authored by: bkazez on Dec 18, '04 10:51:50AM

Sorry, the backslash in my post wasn't preserved. You should replace backslash-quote with percent-two-two.

---
http://ben.kazez.com/



[ Reply to This | # ]
re: %-encoding characters
Authored by: nicksay on Dec 18, '04 07:26:32PM
Actually, it's not always a good idea to %-encode characters. It depends on how you're going to open the url. If you're going to directly tell Safari to make a new document and set the path to the url, then, yes, you'll want to %-encode characters:
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
However, if you're going to use the open location command to let the system open the url in the default application using the default "Open links from applications" behavior (see your browser's preferences), then you shouldn't %-encode characters. The system (or browser, not sure which) will try to re-encode the url, replacing the % with %25 leaving you with %2522, which messes up your search. So, you'd want to leave it unencoded:
set theURL to "http://www.google.com/search?q=\"" & name of thePerson & "\""
tell application "System Events" to open location theURL
(See my comment above about why tell application "System Events" to is necessary.)

[ Reply to This | # ]
re: %-encoding characters
Authored by: koncept on Dec 20, '04 12:47:50PM
I altered your last handler to the following to account for spaces:

on perform action for thePerson with fone
  set od to AppleScript's text item delimiters
  set newDelim to space
  set theURL to "http://www.google.com/search?q=" & name of thePerson
  set AppleScript's text item delimiters to newDelim
  set ti to text items of theURL
  set AppleScript's text item delimiters to "%20"
  set urlEncoded to ti as string
  set AppleScript's text item delimiters to od
  do shell script ("open" & space & quoted form of urlEncoded)
  return true
end perform action


[ Reply to This | # ]