Here’s a focused 2‑week plan with small daily exercises aimed at “AppleScript in Keyboard Maestro,” not generic theory. This assumes 20–40 minutes per day.
This tutorial is targeted to users who are new to Keyboard Maestro and also AppleScript (i.e., me).
Week 1 – AppleScript foundations
Day 1 – Setup and “Hello, AppleScript”
Goal: Get comfortable in Script Editor.
- Read the macOS Automation “First Tutorial” section once.[1]
- In Script Editor, type and run:
beepsay "Hello from AppleScript"
- Play with mistakes on purpose and read the error messages.
Exercise: Write a script that shows a dialog “Good morning” and then beeps 3 times.
Day 2 – Tell blocks and the Finder
Goal: Learn tell and basic app control.
- Skim the first part of the macOS Automation tutorial that uses Finder as the example.[1:1]
- In Script Editor, open Finder’s dictionary (File → Open Dictionary → Finder) and glance through the entries.[2]
Exercises (run from Script Editor):
- Open a specific folder:
tell application "Finder" to open folder "Documents" of home. - Make Finder the frontmost app and select a file on your Desktop.
Day 3 – Variables and simple logic
Goal: Store values and make decisions.
- Read one short beginner article or section (e.g., MacScripter “AppleScript for Beginners I” intro).[3]
- Practice:
set userName to "Jane"set hourNow to (current date)'s time(or just use a number)- Use
ifto choose between “Good morning” vs “Good evening.”
Exercise: Script asks for a folder (using choose folder) and then opens it in Finder.
Day 4 – Working with text
Goal: Manipulate strings you’ll later pass to/from KM.
- From the Language Guide or beginner material, review text and lists basics.[4][3:1]
- Practice:
- Concatenate text:
set msg to "Hello, " & userName. - Get a substring using
text 1 thru 5 of.
- Concatenate text:
Exercise: Ask the user for some text (via display dialog), convert it to uppercase or prepend a timestamp, then display the result.
Day 5 – Using app dictionaries you care about
Goal: Explore scripting for one or two real apps you use.
- Open Script Editor dictionary for an app you actually automate (Mail, Safari, Things, Terminal, etc.).[2:1]
- Also skim Apple’s doc on automating Terminal if Terminal is relevant.[5]
Exercise: For one app:
- Write a script that does one small real thing (e.g., in Safari: open a URL and make the window frontmost; in Mail: create a draft email).
Day 6 – AppleScript + Terminal or Automator (optional but useful)
Goal: See AppleScript talking to other automation tools.
- Read Apple support article on using AppleScript with Terminal or Automator (pick whichever you care about more).[6][5:1]
Exercise (pick one):
- AppleScript telling Terminal to run a simple command (
lsin a folder).[5:2] - AppleScript running an Automator workflow.[6:1]
Day 7 – Review and mini-project
Goal: Consolidate week 1.
- Review your scripts from Days 1–6; clean them up and comment them using
(* ... *).[3:2]
Mini‑project (keep it simple, but real):
- A single AppleScript that:
- Asks you to choose a project folder.
- Opens it in Finder and optionally in Terminal or your editor.
You’ll plug a version of this into Keyboard Maestro next week.
Week 2 – AppleScript inside Keyboard Maestro
Day 8 – Keyboard Maestro + AppleScript basics
Goal: Learn the mechanics of “Execute AppleScript” inside KM.
- Read the Keyboard Maestro wiki page “Execute an AppleScript”.[7]
- Watch the short KM + AppleScript YouTube example (change background macro).[8]
Exercise:
- Create a KM macro:
- Trigger: hot key.
- Action: “Execute an AppleScript” (text, not file).
- Script: something simple like
display dialog "Triggered from Keyboard Maestro".
Day 9 – Passing data from KM to AppleScript
Goal: Use KM variables inside AppleScript.
- Read “Using AppleScript to Get and Set Keyboard Maestro Variables.”[9]
- Skim KM manual “Scripting” section to see how KM variables map to environment variables.[10]
Exercise:
- In KM, set a variable
File_Nameto some text. - In an “Execute AppleScript” action, use:
tell application "Keyboard Maestro Engine" to set v to getvariable "File_Name"[9:1]
- Show
vin a dialog or manipulate it.
Day 10 – Passing data back to KM
Goal: Return results from AppleScript to the macro.
- Revisit the KM AppleScript wiki examples that set KM variables.[9:2]
Exercise:
- Macro flow:
- KM gets some text (e.g., from a Prompt for User Input or clipboard).
- “Execute AppleScript” reads that text (
getvariable). - Script transforms it (e.g., changes case, adds date).
- Script writes it back to a KM variable with
setvariable.[9:3] - KM shows the result in a notification or inserts it.
Day 11 – Working with local/instance variables
Goal: Use local/instance variables so macros stay clean.
- Read the “Local & Instance Variables” section of the KM AppleScript page.[9:4]
Exercise:
- Create a macro that:
- Uses a Local variable (
Local__InputText). - Passes the KMINSTANCE into AppleScript.
- AppleScript reads
Local__InputText, processes it, and setsLocal__ResultText.[9:5] - KM then pastes or displays
Local__ResultText.
- Uses a Local variable (
Day 12 – Real‑world macro #1
Goal: Build a practical KM + AppleScript macro you’ll actually use.
Pick something from your daily workflow, for example:
- “Smart project opener”:
- KM: prompt for project name; set variable.
- AppleScript: look up a folder or app set based on that name and open everything you need.
- “Screenshot organizer”:
- KM: trigger macro when you press a hotkey.
- AppleScript: move latest screenshot to a project folder or rename it.
Use the same pattern: KM handles trigger/variables; AppleScript does the app‑level work.[7:1][9:6]
Day 13 – Real‑world macro #2
Goal: A second, smaller macro to reinforce patterns.
Ideas:
- Email helper: KM collects some info, AppleScript creates a pre-filled Mail message.
- Window/layout helper: AppleScript tells Finder/Terminal/your editor to arrange windows for a specific task (similar to the background‑changer example).[8:1]
Focus on:
- Clean, commented AppleScript.
- Clear KM variable naming conventions.
Day 14 – Review, refactor, and “cheat sheet”
Goal: Cement what you learned and create your own reference.
- Revisit AppleScript basics references you actually used (macOS Automation tutorial, Language Guide sections, KM wiki pages).[4:1][1:2][7:2][9:7]
Deliverables for yourself:
- A 1–2 page “AppleScript + KM” cheat sheet with:
View an app’s scripting dictionary in Script Editor on Mac - Apple Support ↩︎ ↩︎ ↩︎
AppleScript for Beginners I - Getting Started & Script Editor - unScripted - MacScripter ↩︎ ↩︎ ↩︎
Automate tasks using AppleScript and Terminal on Mac - Apple Support ↩︎ ↩︎ ↩︎ ↩︎
action:Execute an AppleScript [Keyboard Maestro Wiki] ↩︎ ↩︎ ↩︎
AppleScript [Keyboard Maestro Wiki] ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎ ↩︎