Search code examples
swiftapplescript

Can you execute an Applescript script from a Swift Application


I have a simple AppleScript that sends an email. How can I call it from within a Swift application?

(I wasn't able to find the answer via Google.)


Solution

  • Tested: one can do something like this (arbitrary script path added):

    import Foundation
     
    let task = Process()
    task.launchPath = "/usr/bin/osascript"
    task.arguments = ["~/Desktop/testscript.scpt"]
     
    task.launch()