Using an process to run AppleScript codes with Arguments in Swift

Solution for Using an process to run AppleScript codes with Arguments in Swift
is Given Below:

To run AppleScript using processes in Swift is needed something like this

let process = Process()
if process.isRunning == false {
    let pipe = Pipe()
    process.launchPath = "/usr/bin/osascript"
    process.arguments = ["/Users/user/Documents/activateApplication.scpt"]
    process.standardError = pipe
    process.launch()
}

but how, using processes I can send more arguments? like “Safari” and use this arguments in the destination script?

the activateApplication.scpt is:

on run appName
    tell application appName to activate
end run

This is documented in the osascript man page. Pass the script arguments as additional arguments after the script file, and they will appear as a list in the first (and only) argument of your run handler. Your Swift code would look something like this:

    process.arguments = ["/Users/user/Documents/activateApplication.scpt", "Safari"]

…and your script would look like this:

on run argv
    tell app (item 1 of argv) to activate
end