Deepl Translator 的 Automator 快速操作 (AppleScript)
Posted
技术标签:
【中文标题】Deepl Translator 的 Automator 快速操作 (AppleScript)【英文标题】:Automator Quick Action (AppleScript) for Deepl Translator 【发布时间】:2022-01-16 05:23:16 【问题描述】:我有一个 Automator 快速操作(服务)来从应用程序中获取文本并在 Deepl 网站上打开它们来翻译它们。它有效,但是单词之间的空格被替换为 + 符号。翻译用+号填充,像这样:
“...+in+第三位+on+the+list+of+the+most+...”
这是什么原因造成的?
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
【问题讨论】:
您需要将空格编码为%20
不 +
。
@user3439894 非常感谢!
【参考方案1】:
我会使用来自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
【讨论】:
非常感谢!以上是关于Deepl Translator 的 Automator 快速操作 (AppleScript)的主要内容,如果未能解决你的问题,请参考以下文章
Deep-Trimap-Generation-for-Automatic-Video-Matting-using-GAN