Link Search Menu Expand Document

Running shell scripts and commands

Lines starting with a dollar sign ($) are run as shell commands. Anything after the $ will be executed as /bin/sh -c [your script]. This can be a full path to a shell script file, or a direct command. No output is sent or received by this action, other than the arguments you provide on the “command line.” If the script returns an error, an alert containing the error will be shown when you run the Bunch.

Important: in the case of scripts, ensure that your script has a hashbang (e.g. #!/usr/bin/env ruby, #!/bin/bash, or #!/usr/bin/osascript -l JavaScript) and that it has executable permissions (chmod a+x

Arguments and environment variables

You can specify direct arguments after the command or shell script path. Like the Automator actions above, you can also use - ... lines below the script line to set environment variables. Because the /bin/sh is running outside your user, even the $HOME variable isn’t set by default (but Bunch figures it out and includes it for you). The following environment variables are available:

  • $BUNCH => name of current bunch
  • $BUNCH_DIR => the location of your Bunches from preferences
  • $HOME => path to user home folder
  • $PATH => a basic path is set that includes /usr/local/bin
  • $BUNCH_DND => current state of Do Not Disturb (1 if on, 0 if off)
  • $BUNCH_DOCK => current visibility of Dock (1 if visible, 0 if autohide)
  • $BUNCH_DESKTOP_ICONS => current visibility of Desktop icons (1 if visible, 0 if hidden)

If you need to provide additional environment variables to your script, set it up like:

$ /Users/ttscoff/scripts/myscript.rb
- HOME=/Users/ttscoff
- FOO=bar

These will be the equivalent of an export FOO=bar command prior to running your script. If you set HOME, it will override what Bunch sets. If you set PATH, it will be inserted before (higher priority than) Bunch’s default path in the environment.

As I mentioned, Bunch doesn’t do anything with the output of a command. If you want to react to shell command output, use Automator with a Run Shell Script action. If you want feedback while running, you can always use AppleScript in your shell script:

osascript -e "display notification \"$INFO\""

You can fork a script using the $BUNCH variable. If you have a script with common tasks but you need it to differ between Bunches in some way, do something along the lines of (in Bash):

if [[ $BUNCH == Default ]]; then...

Or Ruby:

if ENV['BUNCH'] == "Default"

Et cetera.