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:
- 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;
- Add a snippet action with
open macappstore://showUpdatesPagefollowed by a carriage return;
- Add a wait interval giving the command some time to finish;
- Add a shortcut with ⌘+W. This will close the terminal tab you created for this command;
- Add one more shortcut with ⌘+Q. This will close the terminal window. This last step is optional, but since I only use terminal.app for these little actions I can safely close it when the action finishes.
To see and optionally install updates via the command line, create another pad that triggers the terminal with these actions:
- Shortcut with ⌘+T;
- Snippet with
sudo softwareupdate -lfollowed by a carriage return;
- Add a wait, but this time choose input;
- Another snippet with
sudo softwareupdate -iaand a carriage return;
- Another wait with input rather than time;
- A shortcut with ⌘+W;
- 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.
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.
#!/usr/bin/osascript -- 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 else 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).
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.
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.