【发布时间】:2015-05-11 09:22:07
【问题描述】:
是否可以在 Swift 中运行 Applescript 并接收返回值? 我有一个类似下面的脚本。如何快速运行它并接收返回值?
global frontApp
set windowTitle to "
tell application "System Events"
set frontApp to first application process whose frontmost is true
end tell
return {frontApp}
我的代码如下
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
attribute \"AXTitle\"\n"
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)!
startAtLoginScript.executeAndReturnError(errorInfo)
你能告诉我我的结果应该在哪里或者我做错了什么吗?如果我打印出 errorInfo 或跟踪结果是一些奇怪的数字。
【问题讨论】:
-
谢谢马特。我见过这个。但是,您给出了一个简短的代码示例,如何运行脚本并在 swift 数组中接收数据?我可以发布我的方法,但结果很奇怪。
标签: macos swift applescript