簡體   English   中英

Deepl Translator 的 Automator 快速操作 (AppleScript)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM