0

I'm not even sure if bash is the most proper way to achieve this but, I need to, programmatically, switch between opened applications on OS X.

I'm thinking about doing a bash program to execute "cmd+tab".

I'm unable to find this on a regular search, so, perhaps someone can point me some directions here?

Jongware
  • 22,200
  • 8
  • 54
  • 100
MEM
  • 30,529
  • 42
  • 121
  • 191
  • I don't think you really want to tab to "the" next program – even doing this manually, I often have to repeat to get the one I *meant*. Are you sure you don't mean "programmatically *activate* one of my opened applications" instead? – Jongware Jun 16 '15 at 08:24
  • This is for a kiosk like application. I will have only two windows opened. One is the browser, and the other is a Mac OS X app. I wish to programmatically switch between them. So, I thought that simply emulate "cmd+tab" would be enough, since no other apps will be opened, and I can set the "first" application to appear, and then, it will be like a switch. – MEM Jun 16 '15 at 08:26
  • http://macscripter.net/viewtopic.php?id=32580 – Mark Setchell Jun 16 '15 at 08:32

1 Answers1

2

You can use Applescript to achieve this.

To focus on a specific application:

tell application "Finder" to activate

And to emulate an actual Cmd+Tab input:

tell application "System Events"
  key down command
  keystroke tab
  key up command
end tell

Applescript files (*.scpt) can be run through the command line with osascript file.scpt.