23 February, 2009

OS X - Running Scripts As Apps

I had a need to run a REBOL script as an application on my Mac. I was tired of constantly opening Terminal, navigating to the right directory, and typing "rebol script.r" every time I wanted to run my script. This post contained my solution. It describes how to open the current folder you're looking at in Finder in the Terminal, but the same principals worked for my problem. 

I created a workflow in Automator with a single "Run Applescript" step. Basically, the Applescript ended up looking like this.
on run {input, parameters} 
 tell application "Terminal"
activate
tell window 1
do script "rebol ~/REBOL/var/script.r"
end tell
end tell

return input
end run
Voila, I exported the workflow as an application via "Save As..." in the file menu in Automator, and running the program opened Terminal and launched my script. Problem solved. It's not the cleanest solution, but it works.

This is applicable to any script you want to run. Python, Ruby, REBOL, whatever you want. You could specify anything in the "do script..." line. You could even whip together an app that prompts you for what script you want to run, and then passes it in as a variable to the Run Applescript step in the workflow. The possibilities abound.

0 comments:

 
 
Copyright © 2015 James Irwin.
Clear by BloggerThemes Design by Diovo.com, with serious alterations by the author.