Is it possible to trigger an Automator script upon text selection on Mac OS X? I.e. if I select some text in any application (e.g. Safari, Eclipse, etc.), it should trigger an Automator script.

I'm open to suggestions using other languages / automation programs.


If the applications are scriptable like safari is, then you can possibly have a Applescript application running and checking if there is a selection. Then respond by running you task or calling the Automator workflow when there is.

Afaik Applications do not send out notifications when text is selected so this would have to work using a periodic check. Which means wthere ould be a delay in when you Applescript Application reacts

Example of Applescript App. (save as Application with stay open checked)

    property oldSelectedText : ""

on idle
        tell application "Safari"

            set selectedText to (do JavaScript "(''+getSelection())" in document 1)
            if selectedText is not "" then
                if oldSelectedText is not equal to selectedText then

                    (* DO STUFF*)

                    set oldSelectedText to selectedText
                    display notification with title "Safari Selection" subtitle selectedText

                end if
            end if
        end tell

    end try

    return 5 -- seconds idle before next check
end idle
  • 1
    Thanks. Any idea how the application PopClip displays a popover menu whenever some text is selected in any application? Period check? – Franck Dernoncourt Jan 2 '15 at 3:07
  • Sorry not a clue and Im afraid it is not an app I would install on my Machines to try and find out. – markhunte Jan 2 '15 at 3:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .