如何在我的应用程序中自定义出现在 运行 AppleScript 上的消息
How do I customize the message that comes up on running AppleScript from within my app
我正在创建一个需要在其他应用程序上执行 AppleScript 的 macOS 应用程序
考虑以下片段。
let myAppleScript = "tell application \"Finder\" to close window 1 where name is \"Documents\""
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: myAppleScript) {
let output = scriptObject.executeAndReturnError(&error)
print("AppleScript output: ", output.stringValue ?? "")
}
第一次执行时,macOS 引发 prompt/dialog 并显示以下消息
“Xcode“ wants access to control “Finder“. Allowing control will provide access to documents and data in “Finder“, and to perform actions within that app.
(当我直接 运行 我的应用程序时,Xcode
当然会被我的应用程序名称替换 - 目前我正在 Xcode 中测试该应用程序。)
我想在此消息中添加另一行,告知用户为什么我的应用需要此权限。
我怎样才能做到这一点? (我看到另一个应用程序这样做,所以我知道这是可能的)。
您必须在 Info.plist
中添加键值对
在源代码视图中添加
<key>NSAppleEventsUsageDescription</key>
<string>$(PRODUCT_NAME) needs to control Finder</string>
在属性列表视图中添加
Privacy - AppleEvents Sending Usage Description
.
字符串 value
是显示给用户的消息。
我正在创建一个需要在其他应用程序上执行 AppleScript 的 macOS 应用程序
考虑以下片段。
let myAppleScript = "tell application \"Finder\" to close window 1 where name is \"Documents\""
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: myAppleScript) {
let output = scriptObject.executeAndReturnError(&error)
print("AppleScript output: ", output.stringValue ?? "")
}
第一次执行时,macOS 引发 prompt/dialog 并显示以下消息
“Xcode“ wants access to control “Finder“. Allowing control will provide access to documents and data in “Finder“, and to perform actions within that app.
(当我直接 运行 我的应用程序时,Xcode
当然会被我的应用程序名称替换 - 目前我正在 Xcode 中测试该应用程序。)
我想在此消息中添加另一行,告知用户为什么我的应用需要此权限。 我怎样才能做到这一点? (我看到另一个应用程序这样做,所以我知道这是可能的)。
您必须在 Info.plist
中添加键值对在源代码视图中添加
<key>NSAppleEventsUsageDescription</key> <string>$(PRODUCT_NAME) needs to control Finder</string>
在属性列表视图中添加
Privacy - AppleEvents Sending Usage Description
.
字符串 value
是显示给用户的消息。