Is it possible to run a Applescript in Swift and receive the return values?
I have a script like the following. How can I run this in swift and receive the return value?
set windowTitle to "
tell application "System Events"
set frontApp to first application process whose frontmost is true
var set: String = "set windowTile to \"\"\n"
var tell: String = "tell application \"System Events\"\n"
var setFrontApp: String = "set frontApp to first application
process whose frontmost is true\n"
var setFrontAppName: String = "set frontAppName to name of frontApp\n"
var tellProcces: String = "tell process frontAppName\n"
var tellFirst: String = "tell (1st window whose value of attribute
\"AXMain\" is true)\n"
var setWindowTitle: String = "set windowTitle to value of
var endTellFirst: String = "end tell\n"
var endTellProcess: String = "end tell\n"
var endTell: String = "end tell"
var startAtLoginScript: NSAppleScript = NSAppleScript(source: tell
+ deleteItem + endTell)!
NSAppleScript is a mostly useless hunk of junk. If you want to integrate your own AppleScript code into your ObjC/Swift project, use the AppleScript-ObjC bridge, which uses standard ObjC messaging and provides automatic bridging between most AS types and their Foundation equivalents:
If you want to execute user-supplied scripts, you generally want to use
NSUserAppleScriptTask. Functionally it's even lamer than
NSAppleScript (no persistence support); however, it is sandbox-friendly whereas
NSAppleScript (which runs in-process) is not.