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


Click here to return to the 're: %-encoding characters' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]