Nicholas Warren
5 minute read

Automation with Scripting: Mac Automation Series Part 2

Automation can save us time and allow us to easily achieve new tasks. MacOS has support for several scripting languages straight out of the box. Using these languages, we can create tools that are more complex and customisable than the built in tools allow for. Scripting is a dense subject, of which this article only scratches the surface. That being said, there are plenty of good web based resources that will help you in your journey to becoming a competent script developer.

This article focusses on scripting languages and their use in automating the Mac. Check out Part 1: Simple Automation to find out how to leverage several standard tools built into MacOS’s GUI (Graphical User Interface). Part 3 looks at Apps that facilitate automation through the use of blocks which perform a specific function and come together to create an application or flow.

GET THE TOOLS FOR FREE

If you would like to use the tools that I have developed for these blogs fill in the form for free access to the download links. I will keep adding tools to this list to support you in your Mac journey so make sure to bookmark the link for future reference.

* indicates a required field.

Privacy Notice

Submitting your email is deemed consent for joining the Airiam mailing list. For more information explaining how we use your information please see our privacy policy.

The Terminal app icon a console prompt.

Shell Scripting

MacOS is built on a UNIX core, which means that it has a standard UNIX terminal available for use. The terminal is a command line system that allows you to type commands to be executed directly. These commands can be expanded into small programs called scripts that will execute a number of these commands. The terminal can be very good at doing those low level repetitive tasks that otherwise would take a lot of mouse clicks to achieve in the GUI (Graphical User Interface). The only downside to using the Terminal is that you need to learn a new programming ‘language’ in order to use it, however lots of information is available on the internet about the various commands and what they do, as well as manual pages built into terminal itself.

Webp Encoding Tool

One of the emerging technologies on the web is next generation image formats that allow for higher quality images at smaller file sizes, making our webpages load faster and look better. Webp is one such file format, however it can be tedious using the supplied command line encoder, especially if we have to create several different versions of the same image at different scales in order to make our web design responsive.

Follow along with the video to learn how to leverage the power of shell scripting to create a utility for encoding a supplied input image into a set of responsive images. The script asks the user for the root dimension (largest required size for the image) and a quality level.

If you would rather you can download it along with the other tools demonstrated in this article for free using the link at the top of this post.

The Script Editor app icon a pencil on a scroll.

AppleScript

AppleScript is another language built into MacOS that allows you to control communication between applications. It uses a more ‘natural’ language model to make its code more readable by us as humans. It’s quite powerful especially when developers expose functions from their apps to interface with AppleScript. Again you have to be prepared to learn the language to get the best out of it, and even though it’s a more natural language system it can still be a challenge to understand. Another great aspect of AppleScript is its ability to incorporate a shell script, so you can get the best of both worlds.

Image Conversion Tool

In the video below we walk through the creation of a great little utility applet in AppleScript that allows us to convert the file format of image files. Of course applications like Adobe photoshop and Affinity Photo allow you to easily do this task, however the applet can acheive the same job with fewer clicks and without having to launch a large program. The applet is quick and simple to use, and may be a great boost to your productivity.

You can follow along to create it yourself or download it along with the other tools demonstrated in this article for free using the link at the top of this post.

JavaScript

MacOS also allows you to use JavaScript to control applications in a very similar way to AppleScript. Its syntactical conventions are less abstracted than AppleScript so the code isn’t as human readable, however JavaScript is one of the main programming languages used in web development so many people are already familiar with it. If you want to learn more about how to use it in the context of automation you can check out the well written Apple documentation.

Changing an App Icon

By default the icons created for applets use the standard script icons, however this can easily get confusing if you have many of them, therefore changing the icon of the app can be very useful. To change the app icon follow the steps below:

  1. Select the script/applet in the Finder.
  2. Select File > Get Info or press ⌘ + I ( Command + I ).
  3. Navigate to your new icon and copy it by pressing ⌘ + C ( Command + C ).
  4. Head back to the Get Info panel and select the icon.
  5. Paste the new icon onto the old one by pressing ⌘ + V ( Command + V ).

App Icons

It’s important to make sure that your icon uses the .png format with transparency in order to conform with Apple’s iconography guidelines. More information can be found at their dedicated page for app icons. You should also ensure a 1024x1024 resolution to maintain visual clarity in all use cases.

Scripting is a very powerful way to automate various aspects of MacOS to build useful tools and utilities that can really boost your productivity. It can be a challenging endeavour to learn the required new ‘language’ but the rewards are numerous and will greatly improve your ability to refine your workflow gaining efficiencies unavailable to you without their use.

In part three of our Mac Automation series we take a look at the apps that aim to give you a similar level of control as scripting but that don’t require the knowledge of a programming language in order to use. Look out for it next month.

Return to blog