我長時間使用firefox作爲PC或Mac上唯一的瀏覽器。 簡而言之,我的問題是:我想用automator創建一個mac服務,使用translate.google.com進行即時翻譯的AppleScript也可以使用 。 什麼使用Safari或Chrome的偉大工程(低於4個或5行腳本)AppleScript:在傳遞給Firefox的URL中編碼任意查詢字符串值
On run {input, parameters}
Tell application "Safari"
activate
try
Open location "https://translate.google.com/#auto/en/" & (the clipboard)
end try
end tell
end run
同樣的事情(腳本)不使用Firefox在所有的工作,我嘗試用不同的方式 規避不可能的問題
On run {input, parameters}
Set theProcess to "Firefox"
Set info to {}
Set y to 0
Set x to 0
Set n to 0
Tell application "Applications/Firefox.app"
activate
Open location "http://translate.google.com/#auto/en/"
end tell
Tell application "System events"
Repeat with theProcess in (process "Firefox")
try
Set info to info & (value of (first attribute whose name is "AXWindows") of theProcess)
end try
end repeats
Set n to count of info
info
end tell
Tell application "System Events" to tell process "Firefox"
Set x to "1"
Set frontmost to true
try
Click menu item "Paste" of menu "Edit" of menu bar 1
end try
Repeat while x is "1" -
If x is "1" then
Keystroke "V" using command down
Set x to "0"
end if
end repeat
end tell
end run
通過複製和粘貼,行動發生在頁面完全加載之前,甚至放慢複製和粘貼過程。 經過多次觀察後,存在剪貼板中包含的文本格式與URL關聯的問題,我對此進行了改進,但目前尚不完善。
tell application "Applications/Firefox.app" to activate
tell application "System Events" to tell process "Firefox"
set frontmost to true
set sentence to text of (the clipboard)
set thesentences to paragraphs of sentence
set thenewsentences to thesentences as string
set the clipboard to thenewsentences
keystroke "t" using command down
keystroke "https://translate.google.com/#auto/fr/" & (the clipboard) & return
end tell
無論如何,如果它與Safari瀏覽器不需要修改任何東西,問題是在Firefox項目,所以如果你可以看看這個問題,這將是我們大家非常有用的。 感謝您的關注。 謝謝你的回答。
@ deek5:那倒是奇怪剛在新的Firefox 50的上約塞米蒂安裝建設14F2105和它的工作如預期(在標籤打開)。 – mklement0