Created
November 2, 2016 09:25
-
-
Save jmgarnier/9cc0c6d442f102c687cf6a5180c815a2 to your computer and use it in GitHub Desktop.
Automator Service for passing selected text (after selection the service from context menu) to google translate (works in Google Chrome, OS X 10.10 still up-to-date) on run
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
-- Automator Service for passing selected text (after selection the service from context menu) to google translate (works in Google Chrome, OS X 10.10 still up-to-date) | |
on run {input} | |
set inputText to input as string | |
tell application "Google Chrome" | |
activate | |
set theUrl to "http://translate.google.com#nl/en/" & inputText | |
if (count every window) = 0 then | |
make new window | |
end if | |
set found to false | |
set theTabIndex to -1 | |
repeat with theWindow in every window | |
set theTabIndex to 0 | |
repeat with theTab in every tab of theWindow | |
set theTabIndex to theTabIndex + 1 | |
if theTab's URL = theUrl then | |
set found to true | |
exit repeat | |
end if | |
end repeat | |
if found then | |
exit repeat | |
end if | |
end repeat | |
if found then | |
tell theTab to reload | |
set theWindow's active tab index to theTabIndex | |
set index of theWindow to 1 | |
else | |
tell window 1 to make new tab with properties {URL:theUrl} | |
end if | |
end tell | |
end run |
1 thing to improve is removing /
and all characters that will make an invalid URL or shortened text
Hey, Any way to make it work with safari? when changing the application to Safari if fails with:
"A class name can’t go after this identifier." in line "set theWindow's active tab index to theTabIndex"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from http://andilabs.github.io/utility/translation/google/automator/os-x/mac-os-x/2015/02/01/mac-os-x-translate-by-google-any-text.html
Then add a global keyboard shortcut:
