URL 中的 AppleScript 哈希符号 (#)
AppleScript Hash Symbol (#) in URL
我有这个 Automator AppleScript 来翻译文本。它有效,但只有一个词。如果我要翻译 select 两个或更多单词,它会将 URL 中的散列 (#) 更改为 %23,就像这样
https://www.deepl.com/translator%23pt/en/
然后我得到一个 404 Not Found。
on run {input, parameters}
open location "https://www.deepl.com/translator#pt/en/" & input
end run
我会使用来自 Encoding and Decoding Text 的“清单 32-7 AppleScriptObjC: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
我有这个 Automator AppleScript 来翻译文本。它有效,但只有一个词。如果我要翻译 select 两个或更多单词,它会将 URL 中的散列 (#) 更改为 %23,就像这样
https://www.deepl.com/translator%23pt/en/
然后我得到一个 404 Not Found。
on run {input, parameters}
open location "https://www.deepl.com/translator#pt/en/" & input
end run
我会使用来自 Encoding and Decoding Text 的“清单 32-7 AppleScriptObjC: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