Skip to main content

AppleScript

Automate macOS applications with AppleScript.

How It Works

In OnText, when you create an AppleScript action, you enter the script body directly without the osascript -e prefix. OnText handles the execution for you.

Important

Do NOT include osascript -e in your AppleScript actions. Just write the script content directly.

Examples

Basic Examples

Show notification:

display notification "{text}" with title "OnText"

Speak text:

say "{text}"

Show dialog:

display dialog "{text}"

Applications

Add to Notes app:

tell application "Notes"
make new note with properties {body:"{text}"}
end tell

Create Calendar event:

tell application "Calendar"
tell calendar "Home"
set startDate to current date
set endDate to startDate + (1 * hours)
make new event with properties {summary:"{text}", start date:startDate, end date:endDate}
end tell
end tell

Add to Reminders:

tell application "Reminders"
tell list "Reminders"
make new reminder with properties {name:"{text}"}
end tell
end tell

Open in Safari:

tell application "Safari"
open location "https://google.com/search?q={text}"
end tell

Clipboard Operations

Set clipboard:

set the clipboard to "{text}"

Paste clipboard:

tell application "System Events"
keystroke "v" using command down
end tell

Using AppleScript from Shell Scripts

If you need to combine shell commands with AppleScript, use a Shell Script action type with the -e option:

# Transform text with shell, then use AppleScript for notification
RESULT=$(echo '{text}' | tr 'a-z' 'A-Z')
osascript -e "display notification \"$RESULT\" with title \"Converted\""
tip

In Shell Script actions, use osascript -e 'your script' for inline AppleScript. For multi-line scripts, use multiple -e options instead of heredoc (<<EOF) syntax.

Tips

Debugging

Test your AppleScripts in Script Editor.app before adding them to OnText.

Permissions

Some AppleScript commands require additional permissions in System Settings → Privacy & Security → Automation.