Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

macos - Mac Swift Cocoa - hdiutil: attach failed - Device not configured

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...