brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: open an app's scripting dictionary to see what AppleScript can do with it

macOS
~/tips/tip-macos-script-editor-scripting-dictionary

Script Editor > Window > Library > double-click the app

Shows which commands and objects an app supports before you write a script for it.

For me the hardest part of AppleScript is guessing what an app will let you do. You don’t have to guess. Every scriptable app ships its own dictionary, and Script Editor shows it.

Script Editor > Window > Library > double-click the app

The dictionary lists the commands and objects the app understands, grouped into suites. Most scriptable apps have at least the Standard Suite, and many add their own. There’s a Language pop-up menu as well, so you can switch the view between AppleScript and JavaScript for Automation terms. Apple’s JXA notes also mention File > Open Dictionary as another way in.

Example: you want a script that grabs the title of the front tab in Safari. Open Safari’s dictionary, look at the window and tab classes, and you’ll find the properties you need, such as the tab’s name and URL, before you write a single line. Same for Music, Mail, Finder or System Events. I’d always start here instead of copying a random snippet from a forum, because the dictionary shows what that app on your Mac supports.

The caveat: not every app is in the Library window. If a scriptable app you want isn’t there, Apple’s guide explains how to add it to the list. And if an app has no dictionary at all, it simply isn’t scriptable that way. Then you’re left with UI scripting through System Events, which clicks buttons for you and breaks easily when the app’s layout changes.

Further reading: Apple: View an app's scripting dictionary in Script Editor, Apple: Add or remove apps from the scripting dictionary

More macOS tips System Settings > Accessibility > Hover Text > When using the pointer A Smart Folder in Notes collects notes by tag, checklist or date Type # in a Mac note to tag it, then filter by tag in the sidebar tmutil isexcluded ~/Projects/app/node_modules Crop an image in Preview by dragging a frame and clicking Crop All macOS tips (99) All topics

Link