Skip to content
"Scripting in Swift" demo for FinMacAdmin meetup 25.04.2019
Branch: master
Clone or download

Scripting in Swift Demo

"Scripting in Swift" demo for FinMacAdmin meetup 25.04.2019.

The demo script DefaultMailApp.swift can be used for setting up default email application (macOS Mail or MS Outlook). Try DefaultMailAppOnlyUI.swift if you only want test the UI.


  • Xcode 9/10 or Xcode Command Line Tools installed


Install Xcode or Xcode Command Line Tools.

Tip: Install Xcode Command Line Tools by running swift in Terminal app.

Download or git clone this repo.


Hello Cleveland example:

$ ./Hello.swift

Arguments example:

$ ./Arguments.swift

Empty window example:

$ ./EmptyWindow.swift

Popup button example:

$ ./PopUpButton.swift

GUI example (button functionality disabled):

$ ./DefaultMailAppOnlyUI.swift

Choose default email app example:

$ ./DefaultMailApp.swift

Default email app

Demo app

Default email app configuration

DefaultMailApp.swift struct DefaultApp uses Launch Services API for changing default email application. See details below.

Apple documentation:

macOS Mail Launch Services handlers:

MS Outlook Launch Services handlers:         

macOS Mail URL Scheme:


MS Outlook URL Scheme:


Wrapper script

Most of the macOS management tools execute scripts with root privileges. If you want to run scripts with management tool in current user context you can use the script.

Replace # >>> Add script contents here <<< row in script with Swift script and test:

$ sudo path/to/

Munki makepkginfo command example

$ makepkginfo --name SwiftScriptTest \
--displayname "Swift Script Test" \
--nopkg --pkgvers=1.0 \ \
--OnDemand > swift_test.pkginfo

Additional information

  • GUI scripts are missing all the constraints related things
  • Menu bar displays the active app name as "swift" in GUI scripts
  • Scripts have been tested on 10.14 & 10.13
You can’t perform that action at this time.