Skip to content

Instantly share code, notes, and snippets.

@alanhg

alanhg/sound.scpt

Last active Apr 10, 2021
Embed
What would you like to do?
switch input or output by applescript
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