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


Click here to return to the 'Modification: use default browser, merge address lookup scripts' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Modification: use default browser, merge address lookup scripts
Authored by: bhorrock on Feb 22, '05 01:23:19PM
Here is a modification that merges the personal and business scripts into one script.
Features:
  • 'work' addresses use the business lookup
  • 'home' and 'other' use the personal lookup
  • Supports both French and English labels
  • Uses the default browser
  • Bug fixing to handle some missing values

using terms from application "Address Book"
	on action property
		return "address"
	end action property
	
	on action title for aPerson with aaddress
		return "Canada 411 Lookup"
	end action title
	
	on should enable action for aPerson with aaddress
        return true
	end should enable action
	
	on perform action for aPerson with aaddress
	   (* set "as string" so we don't leave references to missing values hanging *)
		 set cit to city of aaddress        as string
		 set org to organization of aPerson as string
         set prov to state of aaddress      as string
         set ln to last name of aPerson     as string
         set fn to first name of aPerson    as string 

                    
        set def_browser to displayed name of (info for alias getDefaultBrowser())  
      (*  display dialog "default browser: " & def_browser *)

        
        (* What type of address *)
        set atype to label of aaddress

        if atype is "work" or "travail" then
            set query to "http://canada411.yellowpages.ca/searchBusiness.do?srchtype=business&sType=simpleSearch&action=homeSearch&step=getDirectory&Se=smp"
            if org is missing value then 
                set query to my queryWithParam(query, "what", ln)
            else
                set query to my queryWithParam(query, "what", org)
            end if
            
            set query to my queryWithParam(query, "city", cit)
        else
            set query to "http://findaperson.canada411.ca/search/Find_Person?"
            set query to my queryWithParam(query, "firstname", fn)
            set query to my queryWithParam(query, "name", ln)
            set query to my queryWithParam(query, "city_zip", cit)
            set query to my queryWithParam(query, "state_id", prov)             
        end if

        
		set AppleScript's text item delimiters to ""
		tell application def_browser
			activate
			open location (query)
		end tell
	end perform action
	
	
    on getDefaultBrowser()
       set creatorType to word -1 of (do shell script  "defaults read com.apple.LaunchServices |grep -C5 U:http | grep -w LSBundleSignature")
       set {text:creatorType} to (text of creatorType) as text
       tell application "Finder"
          set {defBrowserName, browserContainerAlias} to {name, container} of application file id creatorType
       end tell
       return (browserContainerAlias as text) & defBrowserName
    end getDefaultBrowser

    on queryWithParam(query, param, val)    
        if (val = "missing value" ) or (param is missing value ) then
            return query
        end if
        if query ends with "?" or "&" then
            set retval to query & param & "=" & val
        else
            set retval to query & "&" & param & "=" & val
        end if
        return retval
    end queryWithParam

end using terms from




[ Reply to This | # ]
Modification: use default browser, merge address lookup scripts
Authored by: miles_thatsme on Feb 23, '05 12:41:13AM

Awesome! Much better. Thanks very much.



[ Reply to This | # ]