Last active
November 6, 2023 09:26
-
-
Save JurajNyiri/df4bacd1ccfc00105843e67f09b2fc80 to your computer and use it in GitHub Desktop.
UTM Pass USB Device via apple script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---- 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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had the same problem. And solved it in the same way.