-
-
Save JurajNyiri/df4bacd1ccfc00105843e67f09b2fc80 to your computer and use it in GitHub Desktop.
#---- MODIFY BELOW ----# | |
set application_name to "Home Assistant" # Set to your UTM VM Name | |
set button_name to "USB" #Description of the button, can be found by using Accessibility Inspector from Xcode, you probably want this set to "USB" | |
set usb_select to "Conbee" #Name of the device you wish to pass to VM | |
#---- MODIFY ABOVE ----# | |
#---- APPLICATION CODE, DO NOT TOUCH BELOW----# | |
set foundVM to false | |
repeat while foundVM = false | |
log "Looking for UTM..." | |
tell application "System Events" | |
repeat with theProcess in processes | |
if not background only of theProcess then | |
tell theProcess | |
set processName to name | |
set theWindows to windows | |
end tell | |
set windowsCount to count of theWindows | |
if processName is "UTM" then | |
if windowsCount is greater than 0 then | |
repeat with theWindow in theWindows | |
log "Looking for VM..." | |
set window_name to name of theWindow | |
if window_name is application_name then | |
set foundVM to true | |
log "VM found, trying to click the button..." | |
tell theProcess | |
set frontmost to true | |
repeat with theButton in button of toolbar 1 of theWindow | |
set button_description to description of theButton | |
if button_description is button_name then | |
log button_description | |
click theButton | |
keystroke usb_select | |
key code 36 | |
end if | |
end repeat | |
end tell | |
end if | |
end repeat | |
end if | |
end if | |
end if | |
end repeat | |
end tell | |
end repeat |
Hi!
First of all, thanks for the script! I have an problem loading a USB bluetooth device on boot in my UTM instance of HASS.
I get the script to work all fine if i start UTM first, wait untill start, but when i add it to my login items and run it on boot i get this error message:
"The Action to run applescript ecountered an error can't get item 32 of every process"
Any idea?
I also have an Automator app for running my UTM Hass VM on boot.
So i guess maybe the script run before UTM har started fully.
What do you think?
Best regards,
Måns
This was solved by adding a 30 second delay in the beginning of the script "delay 30"
Thank you so much for your script! It works perfectly.
I added a:
tell application "Finder"
set visible of process "UTM" to false
end tell
once the USB has been changed to hide the UTM application.
Also, for some reason, the command
open "utm://start?name=HAOS"
only opens UTM (not the VM) if it's not running OR start the VM if it's running.
So I had to add UTM as a login item, and add a timer in the AppleScript to wait for it to start, then open and change the USB.
Have you encountered the same issues before?
Thank you so much for your script! It works perfectly. I added a:
tell application "Finder" set visible of process "UTM" to false end tell
once the USB has been changed to hide the UTM application.
Also, for some reason, the command
open "utm://start?name=HAOS"
only opens UTM (not the VM) if it's not running OR start the VM if it's running. So I had to add UTM as a login item, and add a timer in the AppleScript to wait for it to start, then open and change the USB. Have you encountered the same issues before?
I had the same problem. And solved it in the same way.
Thank you for this! I used it with a twist. I had already setup the shortcut to call UTM URL to launch my Home Assistant VM. I edited that shortcut and added a "wait 30 secs" so the VM was up and then added "run apple script" and pasted your code in w/appropriate changes to start sharing the USB for my SkyConnect device. Works! Thank you @Nystro0m
How to run:
application_name
to your VM nameusb_select
to the prefix (or exact match) of your USB device, for example if you are using ConBee II, you can put inconbee
orcon
as long as you do not have other device likeconnected usb device
, it basically just writes the text and hits enter after context menu is shown.