MacOS – How to bring an application made in Automator to the foreground upon launch

applescriptautomatormacos

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?

Best Answer

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.