[英]My app crashes with no error message how can I find out where this comes from?
[英]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會使用以下消息引發提示/對話框
“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
是顯示給用戶的消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.