我有一個 Automator 快速操作(服務)來從應用程式中獲取文本并在 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
uj5u.com熱心網友回復:
我將使用來自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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/382410.html
上一篇:無法運行vpnc命令
下一篇:在開始時突出顯示導航視圖
