Table of contents
- What is AppleScript?
- Why Learn AppleScript?
- How to Open Script Editor
- Writing Your First AppleScript
- Breaking Down the Script
- Controlling Finder with AppleScript
- Breaking Down the Script
- Running AppleScripts from Anywhere
- Conclusion
What is AppleScript?
AppleScript is a scripting language created by Apple. It allows you to automate tasks on macOS by controlling your computer and interacting with apps like Safari, Finder, or Mail. For example, you can tell your computer to open an app, click a button, or even send an email automatically.
In this tutorial, we'll walk through the basics of AppleScript so you can start writing your first simple scripts.
Why Learn AppleScript?
AppleScript is useful because:
- Automating tasks: Save time by automating repetitive tasks, like renaming files or organizing folders.
- Controlling apps: You can tell apps to do things automatically.
- Simplicity: Itβs written in plain English, so itβs relatively easy to understand.
How to Open Script Editor
To write AppleScript, youβll need to use the Script Editor, which comes with macOS.
- Press Command + Space to open Spotlight.
- Type Script Editor and hit Enter.
- You should now see a window with a space to write scripts.
Writing Your First AppleScript
Let's start with a simple script to make your computer talk. This is a fun way to see AppleScript in action!
In the Script Editor, type the following:
01: say "Hello, world!"Click the Run button (it looks like a play button at the top of the window).
Your computer should say "Hello, world!" out loud.
Breaking Down the Script
say
is a command that makes your Mac speak."Hello, world!"
is the text you want it to say. You can change the text to whatever you want!
Controlling Finder with AppleScript
Finder is the app you use to browse your files. You can control Finder using AppleScript. For example, you can make a new folder on your desktop:
In the Script Editor, type:
01: tell application "Finder" 02: make new folder at desktop with properties {name:"My New Folder"} 03: end tellClick Run.
This script tells Finder to create a folder called "My New Folder" on your desktop.
Breaking Down the Script
tell application "Finder"
tells the Finder app that you want to give it commands.make new folder at desktop
creates a folder on your desktop.{name:"My New Folder"}
gives the folder a name.
Running AppleScripts from Anywhere
Instead of opening Script Editor each time, you can save your script as an app or add it to your menu bar for quick access.
- Click File > Export in Script Editor.
- Select Application as the file format.
- Give it a name and save it somewhere on your Mac.
Now, whenever you run that file, the script will execute automatically.
Conclusion
Youβve just written your first AppleScripts! You learned how to:
- Make your computer speak.
- Create a new folder on your desktop using Finder.
In the next part of the tutorial, weβll dive deeper into more useful commands and how to interact with other apps on your Mac.
Feel free to play around with the examples and change things. In AppleScript, trial and error is a great way to learn!
Here is another article you might like π Periodically Run GitHub Actions: A Guide To Scheduled Workflows