I found a way to open Terminal.app very usefully as:

osascript -e \'tell application "Terminal" to do script "cd myfolder && ./something.sh param1"\'

If it were executed from a terminal window then everything is fine - at least for every case that I test. Howeer I run this command from a Node.js server because only that I can trigger a script in a terminal window. But here is the trouble: when it's executed, the Terminal window is behind my Chrome Browser.

How can this window be surely set on the top? I noticed that the window can be surely on top of other Terminal windows but how to set it on top of all other windows?

For example, the window is below Chrome and very hard to be seen:

enter image description here



Use the AppleScript command activate to bring the Terminal.app application to the front:

tell application "Terminal"
end tell

Using osascript this becomes:

osascript -e 'tell application "Terminal" to activate'
  • Is it possible to do that in one line? Because I have to trigger this in a node.js function. – AGamePlayer Sep 10 '15 at 16:45
  • I have added an osascript equivalent. – Graham Miln Sep 10 '15 at 18:21
  • osascript -e 'tell application "Terminal" to activate and to do script "cd myfolder && ./something.sh param1"' Is this correct? – AGamePlayer Sep 11 '15 at 12:27
  • 1
    The simplest solution is to run osascript twice from JavaScript. Once to start your script and again to bring Terminal.app to the front. – Graham Miln Sep 11 '15 at 13:03
  • 1
    Alternative to running osascript twice is running it once with 2 -e commands, like so: osascript -e 'tell application "Terminal" to activate' -e 'tell application "Terminal" to do script "..."' – Hugues M. May 20 '17 at 23:14

You must log in to answer this question.

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