我有這個 Automator AppleScript 來翻譯文本。它有效,但只有一個詞。如果我選擇兩個或更多單詞進行翻譯,它會將 URL 中的哈希 (#) 更改為 #,如下所示
https://www.deepl.com/translator#pt/en/
我得到一個 404 Not Found。
on run {input, parameters}
open location "https://www.deepl.com/translator#pt/en/" & input
end run
uj5u.com熱心網友回復:
我將使用來自Encoding and Decoding Text 的“清單 32-7 AppleScriptObjC:URL 編碼文本的處理程式” 。
示例 AppleScript 代碼:
use framework "Foundation"
use scripting additions
on run {input, parameters}
open location "https://www.deepl.com/translator#pt/en/" & encodeText(input as string)
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/houduan/379607.html
標籤:javascript 苹果系统 苹果文字 翻译
