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: export an AppleScript as an app, and tick Stay open for scripts that keep working

macOS
~/tips/tip-macos-script-editor-save-as-app

Script Editor > File > Export > File Format: Application

Turns a script into a double-clickable app that can stay open and repeat its work.

A script you have to open in Script Editor and run by hand isn’t really automation. Script Editor can wrap it in an app instead, so you double-click it in the Finder like any other program, or put it in your Login Items.

Script Editor > File > Export > File Format: Application

Pick a name and a folder, set File Format to Application and choose your options. Show startup screen shows the script’s description with Run and Quit buttons first. Stay open after run handler keeps the app running until you quit it, which is what you need when the script has an idle handler. Run-only saves only the compiled version, without the readable source.

The Stay open option is the interesting one. Normally a script app runs once and quits. A stay-open app with an idle handler gets called again and again, and the number the handler returns is how many seconds to wait before the next round:

on idle
    -- check something, do the work
    return 300
end idle

That gives you a small watcher that checks something every five minutes for as long as the app runs. For a job like that I’d reach for this before I’d write a launchd job.

The caveat is Run-only. It leaves the script source out of the app bundle, so if you lose your original script file, you can’t edit that app any more. Keep the source file next to it, or skip Run-only for your own tools. It’s meant for when you don’t want people reading your code, which is rarely the case at home.

Further reading: Apple: Save a script as an app in Script Editor, AppleScript Language Guide: About Handlers

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