• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: percent encoding handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: percent encoding handler


  • Subject: Re: percent encoding handler
  • From: 2551phil <email@hidden>
  • Date: Sun, 10 Jul 2016 14:44:14 +0700

Thx, Shane.

I really must start developing the habit of looking up Cocoa methods when I’m thinking about AppleScript.


phil




On 10 Jul 2016, at 14:37, Shane Stanley <email@hidden> wrote:

On 10 Jul 2016, at 5:24 PM, 2551phil <email@hidden> wrote:

Has anyone got a quick and dirty percent encoding handler?

i.e. I want to turn this:


tell application "Finder"
activate
end tell


into this:

tell application "Finder" activate end tell


I thought I’d seen one on this list in the past, but my searches have turned up a "missing value”. :p  

How you do it depends a bit on what the purpose is. In this case, I suspect you want:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set aString to current application's NSString's stringWithString:"The time has come for all good “men”"
set aString to (aString's stringByAddingPercentEncodingWithAllowedCharacters:(current application's NSCharacterSet's URLQueryAllowedCharacterSet())) as text

Which is quick but really quite clean...

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users This email sent to email@hidden
References: 
 >percent encoding handler (From: 2551phil <email@hidden>)
 >Re: percent encoding handler (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: percent encoding handler
  • Next by Date: Re: percent encoding handler
  • Previous by thread: Re: percent encoding handler
  • Next by thread: Re: percent encoding handler
  • Index(es):
    • Date
    • Thread