How to run a set of terminal commands using one click

automatorterminal

So I have this program I use to watch movies on my Apple TV that runs from my Mac in Terminal and goes to the TV. Well whenever you wanna start the server up you have to run a set of commands in Terminal.

$ cd Desktop
$ cd PopcornTV
$ sudo npm install
$ sudo node atv.js

These commands start the server which my Apple TV than connects too. Is there anyway I can make a Automator Application or anything of that sort that will run these commands for me when I click a button.

Best Answer

Running it in an apple script is not that bad. you just have to run the entire script as root because sudo requires user interaction. if you do an apple script like this one:

do shell script "cd ~/Desktop/PopcornTV && /path/to/npm install && /path/to/node atv.js" with administrator privileges 

replace then/path/to/npm and /path/to/node with the output of which npm and which node

it will open up a dialogue and ask you for your password.