tldr/pages/osx/osascript.md

29 lines
733 B
Markdown
Raw Normal View History

# osascript
> Run AppleScript or JavaScript for Automation (JXA) from the command-line.
> More information: <https://ss64.com/osx/osascript.html>.
- Run an AppleScript command:
2022-02-14 11:21:43 +00:00
`osascript -e "{{say 'Hello world'}}"`
- Run multiple AppleScript commands:
2022-02-14 11:21:43 +00:00
`osascript -e "{{say 'Hello'}}" -e "{{say 'world'}}"`
- Run a compiled (`*.scpt`), bundled (`*.scptd`), or plaintext (`*.applescript`) AppleScript file:
`osascript {{path/to/apple.scpt}}`
- Get the bundle identifier of an application (useful for `open -b`):
`osascript -e 'id of app "{{Application}}"'`
- Run a JavaScript command:
2022-02-14 11:21:43 +00:00
`osascript -l JavaScript -e "{{console.log('Hello world');}}"`
- Run a JavaScript file:
`osascript -l JavaScript {{path/to/script.js}}`