I'm writing a macOS Cocoa app using Swift that allows a user to build macOS installation media using a macOS installation .app package. It works by executing the createinstallmedia
binary embedded in the .app package. I'm pretty new to macOS development in general (coming from C# and Python) and have no clue how to achieve this while capturing and reporting status & percentage to the user.
Here's some information that might be beneficial:
- Using macOS 10.15.7 as dev environment
- Programming under Xcode 10.3 (for compatibility reasons)
- Output app is NOT sandboxed
The command needs to be run with administrator privileges, so I can't just create a Process()
instance, call the command and expect it to work. I need macOS to prompt the user for their password so that the commands to write the installer can be run.
The command to be run is formed like this:
let volumePrefix = "/Volumes/"
// Generate the command to run
let source = selectedInstaller // From path selector; in UI
let destination = volumePrefix + targetDevicePopupButton.titleOfSelectedItem!
// Make path bash-friendly
let sourcePath = source.replacingOccurrences(of: " ", with: "\\\\ ")
let destinationPath = destination.replacingOccurrences(of: " ", with: "\\\\ ")
let toolexec = sourcePath + createinstallmedia_executablePath + " --volume " + destinationPath + " --nointeraction"
TL;DR:
Basically, the question boils down to this: How can I run commands with admin privileges, and capture output/progress from them? (Without using osascript
; I've been having output problems with that). Is there a way to show the default macOS authentication dialog with a custom prompt?
I suck at asking questions, and I really hope this doesn't get poorly received. If I wrote/did something wrong, please inform me, because this is new territory for me.