I am creating a MacOS app that automatically installs .dmg's in user Applications folder (copies .app in a dmg to /Applications). But I need to somehow attach the selected .dmg image. I have tried doing this:
func dragViewDidReceive(fileURLs: [URL]) {
for url in fileURLs {
print(url.path)
print(shell("hdiutil attach (url.path)"))
}
}
func shell(_ command: String) -> String {
let task = Process()
let pipe = Pipe()
task.standardOutput = pipe
task.arguments = ["-c", command]
task.launchPath = "/bin/zsh"
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)!
return output
}
But if I select the file (aka call dragViewDidReceive
function) the dmg will not attach and the output for bash command will be hdiutil: attach failed - Device not configured
I also tried using ShellOut:
func dragViewDidReceive(fileURLs: [URL]) {
for url in fileURLs {
print(url.path)
try! shellOut(to: "hdiutil attach (url.path)")
}
}
Which gives the same error. hdiutil: attach failed - Device not configured
Is there any other way how I can attach a .dmg? Or is there any fix for this error using one of these methods?
Thanks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…