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.
JavaScript
x
4
1
on run {input, parameters}
2
open location "https://www.deepl.com/translator#pt/en/" & input
3
end run
4
Advertisement
Answer
I’d use ‘Listing 32-7 AppleScriptObjC: Handler that URL encodes text’ from Encoding and Decoding Text.
Example AppleScript code:
JavaScript
1
14
14
1
use framework "Foundation"
2
use scripting additions
3
4
on run {input, parameters}
5
open location "https://www.deepl.com/translator#pt/en/" & encodeText(input as string)
6
end run
7
8
on encodeText(theText)
9
set theString to stringWithString_(theText) of NSString of current application
10
set theEncoding to NSUTF8StringEncoding of current application
11
set theAdjustedString to stringByAddingPercentEscapesUsingEncoding_(theEncoding) of theString
12
return (theAdjustedString as string)
13
end encodeText
14