Using ScriptRunner plugin

ScriptRunner allows you to run shell scripts right from your workspace. Since shell scripts can do so much, this plugin really adds power to your workspace.

Installation

Installation is the same as for every plugin. You can read more about that in Plugins article.

Get Plugin

The plugin requires macOS 10.15 or newer.

Adding a Script

Simply add ScriptRunner plugin to your workspace, click Edit and write your script.

Editing

You can test the script by clicking Play button (A triangle on it's side pointing to the right). It will show a window with the script output.

Testing

Once you run this script in your workspace, it will show a notification with Hello World message.

Notification

You can configure how to show script output when you click ... button. You can choose to display the output in a window or a notification. By default, the output window is shown on errors only and the output is delivered with a notification.

You can also set a timeout that will stop executing the script after the certain amount of time. By default it's 0 which litterally means no time out and the script will run until completion. This should only be set to a number greater than zero if a script has a potiential to hang (for example: fetching from the Internet a resource, but the Internet connection dies).

Configuration

Plugin Settings

In Settings (a gear button in the top right corner), you can set default option for the $PATH variable.

Settings

This variable controls where programs are searched while running the script. Any command line commands used in the script need to be found in the $PATH variable's path. If your not sure what it should be, open a terminal window using Terminal.app or any other terminal application. On the command line, type:

env | grep "PATH"

Then copy everything after the PATH= and put it in this input box.

Notes on scripts

There are many great resources on the Internet to learn how to write shell scripts. The standard shell for macOS is Zsh. Just search for Zsh tutorials and you will find many!

When creating a script, you will have to keep in mind that ScriptRunner scripts will execute from a directory in the /private/var/folders directory. Therefore, it will have no bearing on where your workspace directories are located. Therefore, the directory path that will be worked in has to be navigated to first before running the rest of the script.

For example, if you have a Wails project you want to compile and it is located at /Users/yourname/project directory, then your script would be:

cd "/Users/yourname/project"
wails build

Notice the first line is to go to the directory containing the project. Then the script can run the compiler to make the program.

If you want to make the script generic, you will have to get the directory to do the work in from the user each time it is ran. You can use programs like BulletinBoard, Pashua, or use an AppleScript in the top of the script to get the path. For example using AppleScript:

read -r -d '' applescriptCode <<'EOF'
   set dialogText to text returned of (display dialog "What directory?" default answer "")
   return dialogText
EOF

dialogText=$(osascript -e "$applescriptCode");
cd "${dialogText}"
wails build