Hi there,
First of all, thanks for making my life easier with DropDMG!
I am trying to use DropDMG using NSTask/Process from within my Swift app, however I always get this error:
Error -1743/errAEEventNotPermitted. The app that is running “dropdmg” needs permission to control DropDMG. You can grant this from System Settings ‣ Privacy & Security ‣ Automation (DropDMG Manual: Granting Automation Access). If you are trying to control DropDMG from Xcode, please see this page for a workaround: DropDMG Manual: Command-line tool
I’ve not been able to trigger the “My App” wants access to control “Drop DMG” message:
Using SD Notary or the Terminal, everything works as expected.
I’ve tried the suggested “tell application "DropDMG" to get version” method:
let appleScript = "tell application \"DropDMG\" to get version"
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: appleScript) {
let result = scriptObject.executeAndReturnError(&error)
if let error = error {
print("Error: \(error)")
} else {
print("Result: \(result.stringValue ?? "No result")")
}
}
It prints the correct version, but still no message pop up.
I also tried automationmodetool enable-automationmode-without-authentication
As a response I get
Setting up machine to allow Automation Mode without requiring user authentication… succeeded.
But for some reason I am still being asked to grand permission.
I’ve also added the NSAppleEventsUsageDescription
key to my info.plist.
My app is not sandboxed (just like SD Notary, so that shouldn’t be a problem)
Here is the basic code I use to run DropDMG:
private static func runDropDMG(version: Version, appURL: URL) {
let dropDMGPath = "/Applications/DropDMG.app/Contents/Frameworks/DropDMGFramework.framework/Versions/A/dropdmg" // Also tried /usr/local/bin/dropdmg
let arguments = [
"--config-name=\"Test-Config\"",
"\"\(appURL.path)\""
]
let process = Process()
process.executableURL = URL(fileURLWithPath: dropDMGPath)
process.arguments = arguments
let outputPipe = Pipe()
let errorPipe = Pipe()
process.standardOutput = outputPipe
process.standardError = errorPipe
do {
try process.run()
process.waitUntilExit()
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: outputData, encoding: .utf8) ?? "No output"
print("Output: \(output)")
let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
let errorOutput = String(data: errorData, encoding: .utf8) ?? "No errors"
print("Errors: \(errorOutput)")
if errorOutput.isEmpty == false {
let alert = NSAlert()
alert.messageText = "Error using DropDMG"
alert.alertStyle = .warning
alert.informativeText = errorOutput
alert.addButton(withTitle: "OK")
alert.runModal()
}
} catch {
print("Failed to run the process: \(error)")
let alert = NSAlert(error: error)
alert.alertStyle = .warning
alert.addButton(withTitle: "OK")
alert.runModal()
}
}
What am I doing wrong? Any suggestions?