Autostart a UTM VM on MacOS

Hello, I use a HAOS image running on an Intel Mac mini to get domotic services at home.
I had a look at UTM official documentation + posted in the Discord support channel to get help, but I still don’t know how to make sure the HAOS VM can start automatically after a reboot of the hardware.
Tried the shortcut method (with utm://start?name=xxx command) and a utmctrl script, but neither of the two method actually launched the VM after a restart.
Currently digging into a plist option, but I am a bit lost when using the launchd command to register the script I created and located in /System/Library/LaunchDaemons
Does anyone have an example of someting actually ok to autostart his/her VM?

1 Like

Make an apple script app that contains
tell application “UTM”
set vm to virtual machine named “Your server”
— start a vm
start vm
end tell

Set Up the Script to Run on Login
Open System Settings (or System Preferences on older macOS versions).
Navigate to General > Login Items.
Click the + button under the “Open at Login” section.
Find and select the application you just saved

Thanks @Johangransby. I also tried this Apple Script method. Unfortunatly it doesn’t start the VM (as the oher solutions described) and it would need someone to log in, this not in my scope.

UTM deprecated the URI scheme due to security issues in v4.5. I switched to using Automator with the UTM CLI instead.

  1. Start “Automator”. Create an “Application” workflow

  1. Search for “Launch Application” action. Double click or drag it into the workflow to add. Select “Other” from the dropdown and then find “UTM.app”.

  1. Search for “Run Shell Script” action. Double click or drag it into the workflow to add.

image

  1. Change the shell script to (replace "Home Assistant" with the name of your Home Assistant VM)
/Applications/UTM.app/Contents/MacOS/utmctl start "Home Assistant"

  1. To test the workflow, make sure UTM is not running or stop the VM. Click “Run” command in the top right of Automator and approve the permission prompt

  1. Verify UTM starts the VM.

  1. Save the Automator workflow as “UTM Start Home Assistant.app”

  1. Open “Login Items” in “Users & Groups” settings

  2. Drag or add the “UTM Start Home Assistant” application into the Login Items (the list UI might be buggy and doesn’t show it immediately, switch between the “Password” and “Login Items” tabs to refresh the list)

  1. Restart the computer. The first time the workflow runs there will be another permissions prompt, approve. Afterwards it shouldn’t prompt anymore.
1 Like

Do you if it is possible to also have UTM connect a specific USB device - in my case the Conbee III stick I use for ZHA?

Nice I will tell this, thanks. I am afraid your method + setting an auto-login user is the only way to have UTM and the VM restarted after a reboot.

Well, did the search myself, and it is possible :slight_smile: