Friday, March 13, 2015

Launching a shell script as an OSX application

Go through this helpful tutorial to get started on understanding how Mac's Automator can make life easier. Look for the section labeled, "Using Variables from your Workflow in AppleScript".

To tidy things up, close the terminal window when we're done.

E.g., I have a script that opens up a file in a text editor and then runs a Ruby script using that same file as input.

[~/scripts/create-reminders.rb]
  
  #!/bin/bash

  home='/Users/dvezzani/Documents/journal/02-feb-2015'
  ruby ${home}/create-ics-reminders.rb > out-reminders.ics
  open -a Reminders out-reminders.ics
[~/Library/Services/create-reminders.workflow]

  on run {input, parameters}

    tell application "Terminal"
      activate
      do script "sh /Users/dvezzani/scripts/create-reminders.sh; exit"
    end tell

    return input
  end run

Then export the workflow as an Application and place in your Applications directory so that you can pull it up with Spotlight.

Other references: