如何在 Swift 中获取应用程序的 属性 "has scripting terminology"
How get the property "has scripting terminology" of an application in Swift
如何获得应用程序的属性“具有脚本术语”?
在 Applescript 中可以这样做
tell application "System Events" to tell process "Safari" to get has scripting terminology
但是我怎样才能在 Swift 中得到这个?
感谢 user3439894 你是对的
下面的代码回答了这个问题
func appHasScriptingTerminology(app: NSRunningApplication) -> Bool?{
guard let infoPlist = Bundle.init(url: app.bundleURL!)?.infoDictionary else {
//can't get Info.plist
return nil
}
if infoPlist["OSAScriptingDefinition"] != nil{
let scriptableValue = infoPlist["NSAppleScriptEnabled"]
if scriptableValue as? Int == 1 || scriptableValue as? String == "Yes" || scriptableValue as? Bool == true{
//has Scripting Terminology
return true
}
}
//don't have Scripting Teminology
return false
}
如何获得应用程序的属性“具有脚本术语”?
在 Applescript 中可以这样做
tell application "System Events" to tell process "Safari" to get has scripting terminology
但是我怎样才能在 Swift 中得到这个?
感谢 user3439894 你是对的
下面的代码回答了这个问题
func appHasScriptingTerminology(app: NSRunningApplication) -> Bool?{
guard let infoPlist = Bundle.init(url: app.bundleURL!)?.infoDictionary else {
//can't get Info.plist
return nil
}
if infoPlist["OSAScriptingDefinition"] != nil{
let scriptableValue = infoPlist["NSAppleScriptEnabled"]
if scriptableValue as? Int == 1 || scriptableValue as? String == "Yes" || scriptableValue as? Bool == true{
//has Scripting Terminology
return true
}
}
//don't have Scripting Teminology
return false
}