Last active
February 18, 2023 23:22
-
-
Save alanhg/21f7fd110e0bdac1d0cce66ca40e78ea to your computer and use it in GitHub Desktop.
switch input or output by applescript
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
set devices to {} | |
tell application "System Preferences" | |
reveal pane id "com.apple.preference.sound" | |
end tell | |
tell application "System Events" | |
tell application process "System Preferences" | |
tell tab group 1 of window "Sound" | |
click radio button "Output" | |
tell table 1 of scroll area 1 | |
set selected_row to (first UI element whose selected is true) | |
set currentOutput to value of text field 1 of selected_row as text | |
repeat with r in rows | |
try | |
set deviceName to value of text field 1 of r as text | |
set end of devices to deviceName | |
end try | |
end repeat | |
end tell | |
end tell | |
end tell | |
end tell | |
if application "System Preferences" is running then | |
tell application "System Preferences" to quit | |
end if | |
set text item delimiters to "‡" | |
set devicesStr to devices as text | |
set comm to "bash ./main.sh" & " \"" & devicesStr & "\""& " \"" & currentOutput & "\""&" output" | |
do shell script comm | |
on run argv | |
set theQuery to item 1 of argv | |
tell application "System Preferences" | |
reveal pane id "com.apple.preference.sound" | |
end tell | |
tell application "System Events" | |
tell application process "System Preferences" | |
tell tab group 1 of window "Sound" | |
click radio button "Output" | |
tell table 1 of scroll area 1 | |
select (row 1 where value of text field 1 is theQuery) | |
end tell | |
end tell | |
end tell | |
end tell | |
if application "System Preferences" is running then | |
tell application "System Preferences" to quit | |
end if | |
return theQuery | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment