№ 05 — AppleScripts Automation · Scripts

Apple
Scripts

A handful of useful scripts for automated startup and stand-alone Mac installations.

macOS Open · MIT Updated 2026
§ 01 — About

A handful of useful scripts for automated startup and stand-alone Mac installations.

Snippets and small scripts collected over years of running Macs as stand-alone installation hosts. Pick what you need, copy, adapt.

If you've ever set up a Mac mini to run an exhibition for six months, you've written scripts like these. Auto-launch on login. Hide the cursor. Restart on a schedule. Reconnect MIDI on boot.

We collected the lot. They're documented, simple, and battle-tested in galleries and showrooms across Europe.

§ 02 — Small tricks

Small tricks.

One-liners and short snippets to drop into your scripts.

01

Wait before the next action

Pause the script for a given number of seconds.

-- wait 10 seconds before the next action
delay 10
02

Set the output volume

Value goes from 0 to 100.

-- change the sound output (from 0 to 100)
set volume output volume 100
03

Open an application

tell application "AppName" to activate
04

Open a file

tell application "Finder" to open POSIX file "/Path/to/file.ext"
05

Open a file or app via shell

Alternative way using the shell.

do shell script "open /Path/to/file.ext"
06

Hide an application

tell application "System Events"
    set visible of process "ProcessName" to false
end tell
07

Shut down the computer

Instant shutdown, ignores app responses.

ignoring application responses
    tell application "Finder"
        shut down
    end tell
end ignoring
08

Reboot with admin privileges

Replace $user and $password with actual credentials.

do shell script "reboot" user name "$user" password "$password" with administrator privileges
09

Bring an app window to focus

tell application "System Events" to tell process "ProcessName"
    perform action "AXRaise" of window 1
end tell
§ 03 — More tricky stuff

More tricky stuff.

Multi-step scripts for installation setups.

01

Auto-connect network MIDI

Tries to connect two Macs via Audio MIDI Setup, retrying every 10 seconds until the other host responds.

-- this will try to connect two computers with the Audio MIDI Setup utility.
-- it will keep trying until the other computer has been detected and connected.
repeat
    tell application "Audio MIDI Setup" to activate
    try
        tell application "System Events" to tell process "Audio MIDI Setup"
            select row 1 of table 1 of scroll area 1 of group 2 of window "MIDI Network Setup"
            click button "Connect" of group 2 of window "MIDI Network Setup"
        end tell
        exit repeat
        return
    on error
        delay 10
    end try
end repeat
02

Send a PJLink command to a video projector

PJLink reference: pjlink.jbmia.or.jp · commands PDF. Does not work on password-protected projectors.

set theIp to "127.0.0.1" -- the projector ip
set theMessage to "POWR 1" -- no need for the %1 prefix nor the (rc) at end of line

-- no need to edit anything below
do shell script "echo \"%1" & theMessage & "\\r\" | nc " & theIp & " 4352"
§ 04 — Stay-open scripts

Stay-open scripts.

Export these as applications with the option Stay open after run handler enabled.

01

Quit and reopen an app every 45 minutes

Adjust the 3-second delay if your app takes longer to quit.

on idle
    set theApp to "AppName"
    tell application theApp to quit
    delay 3
    tell application theApp to activate
    return 2700
end idle
02

Reopen an app after it crashed

Checks every 10 seconds. To prevent the crash reporter from appearing: defaults write com.apple.CrashReporter DialogType none

on idle
    try
        tell application "System Events"
            if not (exists process "ProcessName") then
                -- open a file
                tell application "Finder" to open POSIX file "/Path/to/file.ext"
                -- or open an app
                -- tell application "AppName" to activate
            end if
        end tell
    end try
    return 10
end idle
03

Reopen an app — alternative (macOS 10.9+)

Cleaner syntax for modern macOS versions.

on idle
    try
        if application "AppName" is not running then
            tell application "Finder" to open POSIX file "/Path/to/file.ext"
            -- tell application "AppName" to activate
        end if
    end try
    return 10
end idle
§ 05 — Experimental

Experimental.

Use at your own risk.

Warning

These scripts have not been tested in production. Try them in a safe environment first.

01

Restart a hung app (beach ball)

Detects zombie state via shell ps and restarts the app.

on idle
    set theApp to "AppName"
    set state to ""
    tell application "System Events"
        try
            set PID to unix id of process theApp as Unicode text
            set state to paragraph 2 of (do shell script "ps -p " & quoted form of PID & " | awk '{ print $3 }'")
        end try
    end tell

    if state = "Z" then
        do shell script "kill " & PID
        delay 3
        tell application theApp to activate
        --tell application "Finder" to open POSIX file "/Path/to/file.ext"
    end if
    return 10
end idle
02

Quit an app using too much CPU

Threshold set to 52% in this example.

on idle
    set theApp to "AppName"
    tell application "System Events"
        try
            set PID to unix id of process theApp as Unicode text
        end try
    end tell
    set cpuUsage to (do shell script "ps -c -o %cpu='' -p " & PID) as number
    if cpuUsage is greater than "52.0" then
        tell application theApp to quit
    end if
    return 10
end idle
License

Yours to use.

Released under the MIT license. Use them, modify them, ship them with your installations. No strings, no warranty.