Writing AppleScripts with AI

For those of us that own a Mac, we are probably all too aware of the handy little tool that Apple provides, but very few of ever take the time to use—AppleScript. This incredibly useful scripting language, developed by Apple Inc., has been a part of the Mac OS for decades. The aim of AppleScript is simple; it is designed to automate the actions of the computer and the software that runs on it.

Despite its English-like syntax which makes it relatively easy to understand, especially for non-programmers, it’s still largely overlooked by the general public. In its essence, AppleScript allows you to create a script, or a set of instructions, to control most aspects of your computer. From opening a set of websites every morning, resizing images in a folder, to controlling complex workflows between different applications—AppleScript has you covered.

AppleScript’s capabilities aren’t just limited to automation, it also allows inter-application communication. This allows different software applications to work together seamlessly, making complex tasks simpler, and enhancing productivity for Mac users.

With such potential, I decided to take a different approach to writing AppleScripts—using OpenAI’s ChatGPT. 

In a simple experiment, I asked ChatGPT to create a script that would organize open Finder windows so they would all be visible on the screen. The AI promptly generated a script that resized and repositioned windows according to the screen’s dimensions. As impressive as this was, it didn’t stop there. The AI was also smart enough to suggest that the detection of multiple screens could be achieved based on the screen resolution. 

Intrigued by this, I pushed the boundaries further. I asked the AI to adjust the script such that if there is one window open, it should fill the screen. If there are two, it should split the screen in two, placing the windows side-by-side. If there are four, the screen should be divided into quarters with each window occupying one quarter. In response, the AI generated a revised script that performed exactly as requested.

To test the AI’s understanding of AppleScript further, I gave it a third task. This time, I asked it to create a script that would adjust the screen display if there were three open windows. One window was to take up the left half of the screen, while the other two would fill the right half, one on top and the other at the bottom. Without missing a beat, the AI presented me with a script that accommodated this three-window configuration.

The speed and efficiency with which ChatGPT was able to write these scripts were remarkable. It would have taken me a considerable amount of time to figure out the correct scripting for these tasks, yet the AI did it in a matter of seconds.

So, what’s the takeaway from all this? It’s clear that we are venturing into a whole new world of possibilities with AI. Tools like ChatGPT are making previously daunting tasks much more accessible and manageable. I encourage you all to experiment with some form of AI, whether it be ChatGPT or something else. After all, staying on top of new technologies is the best way to ensure we aren’t left behind.