How to run AppleScript in macOS

Issue #223

Surround script by single quotes

swift
let script = 
"""
tell application "XcodeWay"
    activate
end tell
"""

let command = "osascript -e '\(script)'"

let process = Process()
process.launchPath = "/bin/bash"
process.arguments = ["-c", command]

Run as administrator

In terminal, we can

text
cd ~/Library
sudo mkdir MyNewFolder

In code, we use with administrator privileges, this when run will ask for password or fingerprint

text
do shell script "mkdir MyNewFolder" with administrator privileges
Written by

I’m open source contributor, writer, speaker and product maker.

Start the conversation