Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created July 10, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OKsign/1d86713be8b6c08727041c7fd9952e1b to your computer and use it in GitHub Desktop.
Save OKsign/1d86713be8b6c08727041c7fd9952e1b to your computer and use it in GitHub Desktop.
-- user input
set sound_output_device to "background music"
-- end of user input
if application "System Preferences" is running then
set app_run to 1
else
set app_run to 0
end if
tell application "System Preferences"
delay 2
reveal anchor "output" of pane id "com.apple.preference.sound"
delay 1
activate
end tell
delay 1
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
repeat until activeApp is "System Preferences"
delay 1
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
end repeat
tell application "System Events"
repeat 2 times
delay 0.2
key code 48
end repeat
delay 0.4
keystroke "h"
delay 0.7
keystroke "i"
delay 0.7
keystroke sound_output_device
end tell
tell application activeApp
display notification "Sound Output Device: " & sound_output_device with title "Script 47"
end tell
if app_run is 0 then
delay 1
quit application "System Preferences"
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment