Launch Scripts With Actions

This article is heavily focused on the MAC platform

Launch scripts with Actions

One of Actions’ greatest limitations (yes it has limitations, no point denying it) is its inability to launch user scripts. In the past you’d have to rely on a third party app such as FastScripts, Keyboard Maestro or Alfred for this. Fortunately however, with the introduction of Flows and a little bit of imagination, you can mitigate this limitation.

The key element in this workaround is the terminal. Essentially what you’ll be doing is launching the terminal, pasting a snippet and then closing the terminal again.

Sometimes one line of text is all that it takes to achieve certain tasks, other times you need a little more. I’ll give you a few easy to follow examples so don’t worry if you’ve never used it before.


Show available updates

There are two ways in which you can do this: Launching the Mac App Store or via the command line.

For the Mac App Store, create a pad with Terminal as trigger and add these actions:

  1. Shortcut ⌘+T. This guarantees that even if the terminal isn’t open, it will open and create a new tab. It further guarantees that if the terminal is already open, you won’t be pasting text into an active session;
  2. Add a snippet action with open macappstore://showUpdatesPage followed by a carriage return;
  3. Add a wait interval giving the command some time to finish;
  4. Add a shortcut with ⌘+W. This will close the terminal tab you created for this command;
  5. Add one more shortcut with ⌘+Q. This will close the terminal window. This last step is optional, but since I only use for these little actions I can safely close it when the action finishes.

download this flow

To see and optionally install updates via the command line, create another pad that triggers the terminal with these actions:

TIP: While in edit mode, tap and hold with two fingers the previous pad to duplicate it.
  1. Shortcut with ⌘+T;
  2. Snippet with sudo softwareupdate -l followed by a carriage return;
  3. Add a wait, but this time choose input;
  4. Another snippet with sudo softwareupdate -ia and a carriage return;
  5. Another wait with input rather than time;
  6. A shortcut with ⌘+W;
  7. Optionally a final shortcut with ⌘.Q.

The reason to add two waits with input is so that the command has enough time to finish. When it finishes you’re presented with a list of available updates and which time you can tap the pad again to install all updates. If however there are no updates to install, simply tap the pad with two fingers to skip the install step and then tap with one finger to finish.

download this flow

Connect to My VPN

If you need to have quick access to toggle your VPN on/off, but hate having it up in the menubar, then you’ll love this next example.

Create an empty text file and paste in the following code. Make sure to change the name of the VPN to the same you have setup.


-- Set Defaults
set vpnService to "VPN NAME" -- Set the name of your VPN

-- Set VPN Info
tell application "System Events"
	tell network preferences
		set theVPN to service vpnService
		get configuration of theVPN
		set curState to connected of configuration of theVPN
	end tell
end tell

-- Toggle VPN
tell application "System Events"
	tell network preferences
		if not curState then
			tell theVPN to connect
			tell theVPN to disconnect
		end if
	end tell
end tell

Now save the file as toggleVPN (no extension needed) in an easy to reach location (your Documents maybe). Next, open the terminal and navigate to the file. If you saved it in your Documents, then all you need to do is type cd ~/Documents. Finally, to get the file ready, you need to make it executable. For that, simply type chmod +x toggleVPN. You could also just change the permissions from the Get Info dialogue, but where’s the fun in that?

Now that you have your script ready, open Actions and create a pad similar to the ones above. This time however, in the snippet action, paste the complete path to your script file. If you followed along this far, that would be /Users/pedro/Documents/toggleVPN (don’t forget the carriage return and if your name is not Pedro, then change that too).

download this flow

That’s all that you need to quickly launch a few scripts from Actions. Granted it’s not ideal, but until a time comes when Action Server can run scripts, this will have to suffice.

Follow this guide if you don’t know how to load Flows in Actions

Additional Resources

In case you’d like to glean a few good ideas of what you can accomplish using the terminal alone, I’d recommend reading this great tutorial from Tuts+. This time around the windows users aren’t left out in the cold since scripting with powershell is getting increasingly more robust. Here are a few nice ideas to get you started.

Pedro Lobo

A System Administrator by day and freelance technology writer by night. I put words together to express my opinionated views on software, hardware or anything that strikes my fancy. Said words can be found in a variety of places, among which my blog. When not spending time with my family and taking photographs, I can be found on or Twitter
  • Neal Cassady

    FANTASTIC! Keep it up!

  • Neal Cassady

    Oh wait!

    The “Download for Mac” for the 1st example (Show Updates), appears to install the 2nd example’s script/workflow (Show update & Optionally Install)…

    “Software UpdateCLI.flow” was downloaded. When I imported it into Actions – it tried to run the ‘sudo software update -ia” text snippet, that was inserted.

    No doubt just a mix-up in the links above. I edited the workflow myself, and it works – but others will download, thinking they’re running the 1st one, and end up running the 2nd.

  • Thanks for the warning Neal, we’ll get that fixed ASAP.

    Thanks you also, very happy you’re enjoying it. Stay tuned because we have plenty more in store for you all ;)