[英]Automator Quick Action (AppleScript) for Deepl Translator
我有一个 Automator 快速操作(服务)来从应用程序中获取文本并在 Deepl 网站上打开它们来翻译它们。 它有效,但单词之间的空格被替换为 + 符号。 翻译用 + 号填充,如下所示:
“...+in+第三+位置+on++list+of+of+最+...”
这是什么原因造成的?
on run {input, parameters}
set output to "https://www.deepl.com/translator#pt/en/" & urldecode(input as string)
return output
end run
on urldecode(x)
set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp)'"
do shell script "echo " & quoted form of x & " | ruby -e " & cmd
end urldecode
我会使用来自Encoding and Decoding Text的“列表 32-7 AppleScriptObjC:URL 编码文本的处理程序”。
示例AppleScript代码:
use framework "Foundation"
use scripting additions
on run {input, parameters}
set output to "https://www.deepl.com/translator#pt/en/" & encodeText(input as string)
return output
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.