For my work I use an app called Sublime Text to edit website documents. To open my project in sublime text I drag the folder above the icon and it opens it up in sublime text.

My next step is to run a nodejs script, and after it's run open chrome and navigate to a local url.

My question is - how can I automate that process - meaning I will have a script that I run (command line is fine) that will open the project in sublime text, run the nodejs script (which starts a local web server), open safari to a url.

Is that possible?



Yes, this is possible. The two best options for stitching together Mac applications are AppleScript and Automator.

Given your steps, consider exploring the included Automator application: Applications > Automator.app

Apple's Mac Basics: Automator support note is a good starting point.

The following Actions are likely to help:

  • Display Webpages for opening your default browser and showing a URL
  • Run Shell Script for interacting with node.js
  • Open Finder Items for opening documents in Sublime Text

Automator on OS X 10.9


You can write a bash script. Bash script is like windows batch file.

Here is a little example. Open sublime text and type in:

open -a "Sublime Text 2"
node scriptname.js
open -a "Safari" http://localhost

Save it as script.sh

Then open the terminal and navigate to script folder. Type in next command and hit enter:

chmod u+x script.sh

then run it:


More at bash scripts here and here.


Something like this should be fine:

open -a /Applications/Sublime\ Text.app/ Folder/ && node script.js && open http://localhost:80

Replace Folder/ with folder path and script to the nodejs script path.

  • how do I run this? is there some batch file for mac? – developer82 Feb 14 '14 at 18:50
  • Simply paste it in Terminal, or as already explained in the other answer save it in a .sh file. – gattol Feb 15 '14 at 13:41
  • of course, make sure to alias this for ease of use in the future. – stagl Jan 6 '18 at 19:35

You can save the script with a .command extension: this gives you a file you can "double-click" to open it as an application.

Both way's (use .sh or .command as an extension), you have to make the script executable with chmod in Terminal: chmod u+x ~/MyScript.sh.

  • excellent tip! i've been using a mac and scripting for many years and have yet to hear this one. granted, i try to never use the mouse, but it is still an interesting alternative. – stagl Jan 6 '18 at 19:37

You must log in to answer this question.

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