Automate macOS 12 with the Shortcuts app

Little Helpers

Anchoring Commands in the OS

Before I show you how to build more complex shortcuts, you should take a look under the Shortcut Details icon (three slider bars) at top right (Figure 1). The Details tab lets you choose where each shortcut will be anchored. The options at the top are relevant for macOS. Keep in Menu Bar makes the command available in the operating system menubar at the top of the screen. Use as Quick Action anchors the command in the Finder , which lets you access the command from the Quick Actions menu item in the context menu of folders and files, the Services Menu of an app, or both. If you have a MacBook Pro with a touchbar, you will have an option for that, too.

Figure 1: The tabs under the Shortcut Details icon lets you customize your shortcuts.

If commands need access to resources locally or on the network, they request them on first use. You will find any permissions granted in the Privacy tab, where you can revoke individual permissions or reset data security completely. In the last tab, Setup , you can prepare your own creations by means of prompts for sharing and importing by other users. The Split Screen 2 Apps shortcut makes use of this. The editor offers even better options when you design your own shortcuts.

Zip Files and Folders

The first short example reads folders or files from the Finder and bundles them into a ZIP archive, which it drops in a target folder. If you click the plus icon in the toolbar, the editor comes up with an empty workspace. In the window header, choose a descriptive name and a suitable icon. Now enable the Use as Quick Action option under the shortcut Details tab and optionally enable Finder integration (Figure 2). The first action then appears in the workspace; it initially accepts arbitrary input. You can click on the Any tag to limit the accepted input to media and documents and specify what the command should do if no matching input is found.

Figure 2: Shortcuts anchor themselves in the operating system menubar or as a Quick Action.

Now look for the Make Archive action in the Documents category of the Action library and drag it into the workspace. The action automatically connects to the previous one, which means it accepts the input for processing downstream. Besides ZIP, other archive formats are available for selection. Next, you need to tell the command what to do with the archive. To do this, drag the Move File action into the workspace. It uses the Shortcuts folder as the target by default. Click the appropriate tag, select Replace from the context menu, and set a folder of your choice as the target.

Now when you right-click a folder or file in the Finder and choose Quick Actions from the context menu, if your new shortcut does not show up there, you can activate it in the Customize option. The command will then appear in the quick actions and bundle the transferred files or folders into the ZIP archive, which it delivers to the desired target.

If you want to prepare the command for sharing with other users, add an import question in the Setup section of the Shortcut Details. The main editor window changes and you can select which element the command will prompt for at import time. Now determine the Folder for the Move File action. If you share the command over iCloud or as a shortcut file and another user imports it, they will be prompted to select an individual target folder.

Connecting and Disconnecting Shares

Everything works, in principle, even if the target is a Server Message Block (SMB) share, but to demonstrate the possibilities of shortcuts, I'll duplicate the command and rebuild it so that it explicitly connects to a server by SMB at the beginning, then writes the ZIP archive to a share on the server and disconnects from the server again.

To do this, drag the Connect to Servers action to the second slot on the desktop and enter the path to your share as the target with the smb:// <server>/<share> format. You now want the last action in the command sequence, Move File , to adopt the target dynamically. To do so, right-click on the target folder's name in the last block and select Magic Variable from the context menu. The display in the editor will then change and you can click on the Connected to Servers item farther up in the schedule.

To leverage this action a second time, drag the Eject Disk action into the workspace. Again, use a magic variable here that dynamically reads the output of a previous action and therefore automatically the Connected to Server return value. In the Finder you can see for yourself how the shortcut works. It should now contact your server, write the ZIP archive to it, and then break the connection. With the help of magic variables you can flexibly access the return values of previous actions.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs



Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>
	</a>

<hr>		    
			</div>
		    		</div>

		<div class=