Show pageOld revisionsBacklinksBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== AppleScript ====== ===== Cheatsheet ===== * Get actual path of finder window if opened <code> #!/usr/bin/env bash if ! osascript -s o <<EndOfScript tell application "Finder" try set c to (count of Finder windows) on error message number -1743 error "Privacy settings prevent access to Finder" end try if c is 0 then return POSIX path of (desktop as alias) else return POSIX path of ((target of Finder window 1) as alias) end if end tell EndOfScript then echo "osascript failed" fi </code> * Display an hello world window <code> osascript -e 'tell application "Finder" activate display dialog "Hello, World!" end tell' </code> * Display an hello world window but without sending events to another process <code> osascript <<EndOfScript display dialog "Hello, World!" EndOfScript </code> The useful commands in the Standard Additions extension include: * user interaction: choose file/folder/from list, display dialog/alert/notification * file commands: mount volume * clipboard commands: get the clipboard, set the clipboard to * sound control: set volume, get volume settings * system info When your script uses only these commands, make sure they are not contained in tell blocks. This will avoid unnecessary prompts for access approval. ===== Exempt AppleScript commands ===== Some AppleScript commands are treated differently and will not trigger privacy approval: * activate: launch application and/or bring to front * open: open a file * open location: open a URL * quit: quit the application <code> osascript <<EndOfScript tell application "Firefox" open location "https://scriptingosx.com" end EndOfScript </code> cheatsheet/applescript.txt Last modified: 2024/10/14 20:59by 127.0.0.1