Search code examples
macosterminalfocus

OSX Terminal - Change Application Focus


Is there a way using command line to change the focus to a specific application? If so, do I need the process id or what?

My goal is to run a process that compiles files, and then focuses on the browser window once the files have finished compiling.


Solution

  • If I understand you correctly, this could be done quite easily with open -a. Opening an already-open application brings it to the forefront. The -a option allows you to specify the application you want, so pick your favorite:

    open -a Google\ Chrome
    open -a Safari
    open -a Firefox