I've created an application with AppleScript in Automator.

I've created a Service in Automator which launches the aforementioned app.

The Service is triggered by a keyboard shortcut.

The problem is that upon launch, the application's dialog box has a light gray top bar. I have to click anywhere on the dialog for the dialog to turn to the darker gray, which shows that the app is now selected.

Is it possible for my application to do this automatically?

  • Do you have an activate command after the start of the on run handler? (In the app, not the service.) Nov 19, 2016 at 5:32
  • No, there is no activate command in the entire app. Also, the issue occurs with every one of my Services and it occurs even if I run the Service manually (via the "Services" menu in the top left corner of the screen). Nov 19, 2016 at 5:33

2 Answers 2


Have a look at the activate command in the AppleScript Language Guide Commands Reference.

activate Brings an application to the front, and opens it if it is on the local computer and not already running.

I'd add activate me after the start of the on run handler.

  • activate me solves the problem. I wonder why this is not the default behavior of AppleScript applications. Nov 19, 2016 at 17:53

I see that the OP's question says "an application made in Automator."

But, as an aside, and since this question has most of the right keywords to solve the problem I was having (applications launched from an Automator "Run Shell Script" action showing up behind other open applications)…

If you are launching a GUI application from a shell script action in Automator and find that it is not coming to the foreground and receiving focus, try something like

open -a ProgramName.app --args "$@"

and set "Pass input" to "as arguments". The "$@" will be expanded as an individually-quoted list of the input arguments, separated by whitespace (this is a feature of the Unix shell, not Automator).

This works great, for example, for creating a "Writer" Automator app that launches LibreOffice Writer (open -a LibreOffice.app --args --writer "$@"), and also accepts drag-and-dropped files.

If you are still having trouble getting the application to come to the foreground (maybe it's already open, for example), try appending these lines to the action in Automator:

sleep 1  # adjust as you see fit
osascript <<<'tell application "ProgramName.app" to activate'

You must log in to answer this question.

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