Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

Thanks

share|improve this question
add comment

4 Answers 4

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

share|improve this answer
add comment

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

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

#!/bin/bash
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:

./script.sh

More at bash scripts here and here.

share|improve this answer
add comment

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.

share|improve this answer
    
how do I run this? is there some batch file for mac? –  developer82 Feb 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 at 13:41
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.