Snelle referentie

AppleScript Snelle Naslaggids Spiekbrief

Snelle naslaggids voor AppleScript op macOS: osascript CLI-uitvoering, systeemmeldingen, spraaksynthese, vertragingen en handlers.

· Gepubliceerd

Een snelle naslaggids voor het schrijven en uitvoeren van AppleScript op macOS, van osascript-terminalopdrachten tot UI-automatisering.

AppleScript Uitvoeren

Vanaf de Terminal (osascript)

# Inline-expressie uitvoeren
osascript -e 'display notification "Task completed!" with title "Build Script"'

# Scriptbestand uitvoeren (.scpt of .applescript)
osascript script.scpt

Native Systeemmelding

display notification "Backup finished successfully" with title "System Status" subtitle "Automated Backup"

Commentaar

-- Dit is commentaar op één regel

# Dit is ook commentaar op één regel

(*
Dit is een
commentaarblok over
meerdere regels
*)

Geluid & Audio

Spraaksynthese (say)

-- Standaard systeemstem
say "Build succeeded"

-- Gespecificeerde systeemstem
say "Warning: low battery" using "Zarvox"
say "All systems nominal" using "Samantha"

Systeempiep (Beep)

-- Eén pieptoon
beep

-- Meerdere pieptonen
beep 3

Uitvoeringsvertraging (Delay)

-- Uitvoering 5 seconden onderbreken
delay 5

Handlers (Functies)

on doubleNumber(n)
    return n * 2
end doubleNumber

set doubledValue to my doubleNumber(21)
-- → 42

Handler met Meerdere Argumenten

on showDialog(msg, titleText)
    display alert titleText message msg as informational
end showDialog

my showDialog("Operation completed.", "Success")

Interactie met Applicaties

tell application "Finder"
    activate
    open folder "Documents" of home
end tell

tell application "Google Chrome"
    reload active tab of front window
end tell

Verwante onderwerpen