简体   繁体   中英

AppleScript Hash Symbol (#) in URL

I have this Automator AppleScript to translate texts. It works, but only with one word. If I select two words or more to translate, it changes the hash (#) in the URL to %23, like this

https://www.deepl.com/translator%23pt/en/

and I get a 404 Not Found.

on run {input, parameters}
    open location "https://www.deepl.com/translator#pt/en/" & input
end run

I'd use ' Listing 32-7 AppleScriptObjC: Handler that URL encodes text' from Encoding and Decoding Text .

Example AppleScript code :

use framework "Foundation"
use scripting additions

on run {input, parameters}
    open location "https://www.deepl.com/translator#pt/en/" & encodeText(input as string)
end run

on encodeText(theText)
    set theString to stringWithString_(theText) of NSString of current application
    set theEncoding to NSUTF8StringEncoding of current application
    set theAdjustedString to stringByAddingPercentEscapesUsingEncoding_(theEncoding) of theString
    return (theAdjustedString as string)
end encodeText

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM