我有一个自动快速行动(服务)从应用程序获得文本,并打开他们在Deepl网站上翻译他们。它起作用了,但是单词之间的空格被+符号所取代。翻译中充满了+符号,如下所示:
"...+in+third+place+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发布于 2021-12-12 21:19:19
我将使用“清单32-7 AppleScriptObjC:编解码文本中的文本编码处理程序”。
示例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 encodeTexthttps://stackoverflow.com/questions/70322782
复制相似问题