Skip to content

Instantly share code, notes, and snippets.

@peterwooley
Created November 2, 2016 17:37
Show Gist options
  • Save peterwooley/5b7eb9d66d53103ae464f380ea4fb652 to your computer and use it in GitHub Desktop.
Save peterwooley/5b7eb9d66d53103ae464f380ea4fb652 to your computer and use it in GitHub Desktop.
Run this AppleScript in an Automator service to open selected text in Google Translate.
-- Modified from http://scriptingosx.com/2016/01/build-a-google-translate-service/
on run {input, parameters}
set theText to input as string
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return & linefeed, return, linefeed, "
", character id 8233, character id 8232}
-- list of line break chars from http://stackoverflow.com/questions/12546253/how-to-replace-n-in-applescript#12546965
set splitText to text items of theText
set AppleScript's text item delimiters to {space}
set theText to splitText as text
set AppleScript's text item delimiters to oldDelims
tell application "Safari"
activate
set d to make new document with properties {URL:"https://translate.google.com/#auto/en/" & theText}
end tell
end run
@woodjmichael
Copy link

No issue in macOS 11.3.1 with both the suggested apple scripts and the "Workflow receives current: text" option. Just make sure you create a Quick Action not a Workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment