URL中的AppleScript哈希符号(#)



我有这个Automator AppleScript来翻译文本。它有效,但只有一个词。如果我选择两个或更多的单词进行翻译,它会将URL中的哈希(#(更改为%23,就像这个

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

我得到一个404未找到。

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

我会使用">清单32-7AppleScriptObjC:URL编码文本的处理程序"。

示例 AppleScript 代码

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