Last active
August 22, 2017 10:38
-
-
Save fatihturan/125422a8dc8fd8ba3ad6481b5012d23b to your computer and use it in GitHub Desktop.
Google Translate/Fluid App AppleScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run {input, parameters} | |
set textToTranslate to item 1 of input as string | |
set windowName to “Google Translate” | |
set targetURL to “https://translate.google.com/“ | |
tell application “Google Translate” | |
if (get title of every window) does not contain windowName then | |
open location targetURL | |
else if (get miniaturized of window windowName) then | |
set miniaturized of window windowName to false | |
else | |
if (get title of front window) does not contain windowName then | |
open location targetURL | |
end if | |
end if | |
activate | |
tell front browser window | |
repeat while (loading) | |
delay 0.5 | |
end repeat | |
try | |
do JavaScript “document.getElementById(‘source’).value = \”” & textToTranslate & “\”;” | |
on error | |
set the clipboard to textToTranslate as string | |
delay 1 | |
activate | |
do JavaScript “document.getElementById(‘source’).value = ‘’; document.getElementById(‘source’).focus();” | |
tell application “System Events” | |
keystroke “v” using command down | |
end tell | |
end try | |
end tell | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment