-
-
Save joscha/377275 to your computer and use it in GitHub Desktop.
added temporary file deletion
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
-- TODO: save as a bundle and include the RaopX application: not sure if I can do that since it also contains libsamplerate | |
-- For German OSX | |
set SoundPrefName to "Ton" | |
set InputPanelName to "Eingabe" | |
set OutputPanelName to "Ausgabe" | |
-- For English OSX uncomment this | |
-- set SoundPrefName to "Sound" | |
-- set InputPanelName to "Input" | |
-- set OutputPanelName to "Output" | |
global SoundPrefName, InputPanelName, OutputPanelName | |
on EnsureGuiScriptingEnabled() | |
tell application "System Events" | |
get system attribute "sysv" | |
if result is less than 4144 then -- Mac OS X 10.3.0 | |
tell application me to activate | |
display dialog "This computer cannot run this script" & return & return & "The script uses GUI Scripting technology, which requires an upgrade to Mac OS X 10.3 Panther or newer." with icon caution buttons {"Quit"} default button "Quit" | |
return false | |
end if | |
if not UI elements enabled then | |
tell application me to activate | |
display dialog "GUI Scripting is not enabled" & return & return & "Open System Preferences and check Enable Access for Assistive Devices in the Universal Access preference pane, then run this script again." with icon stop | |
if button returned of result is "OK" then | |
tell application "System Preferences" | |
activate | |
set current pane to pane "com.apple.preference.universalaccess" | |
end tell | |
end if | |
return false | |
end if | |
end tell | |
return true | |
end EnsureGuiScriptingEnabled | |
on IsSystemPreferencesRunning() | |
tell application "System Events" | |
if exists process "System Preferences" then | |
return true | |
else | |
return false | |
end if | |
end tell | |
end IsSystemPreferencesRunning | |
on HideSystemPreferences(shouldHide) | |
tell application "System Events" | |
set visible of process "System Preferences" to not shouldHide | |
end tell | |
end HideSystemPreferences | |
on ActivateSoundPreferencePane() | |
tell application "System Preferences" | |
set current pane to pane "com.apple.preference.sound" | |
end tell | |
end ActivateSoundPreferencePane | |
on ActivatePanelByName(panelName) | |
tell application "System Events" | |
tell process "System Preferences" | |
tell tab group 1 of window SoundPrefName | |
click radio button panelName | |
end tell | |
end tell | |
end tell | |
end ActivatePanelByName | |
on GetSelectedSourceName() | |
tell application "System Events" | |
tell process "System Preferences" | |
set sources to every row of table 1 of scroll area 1 of tab group 1 of window SoundPrefName | |
repeat with source in sources | |
if selected of source is true then | |
return value of text field 1 of source as text | |
end if | |
end repeat | |
end tell | |
end tell | |
end GetSelectedSourceName | |
on SetSelectedSource(sourceName) | |
tell application "System Events" | |
tell process "System Preferences" | |
set sources to every row of table 1 of scroll area 1 of tab group 1 of window SoundPrefName | |
repeat with source in sources | |
if (value of text field 1 of source as text) is equal to sourceName then | |
set selected of source to true | |
return | |
end if | |
end repeat | |
end tell | |
end tell | |
end SetSelectedSource | |
on ActivateInputPanel() | |
ActivatePanelByName(InputPanelName) | |
end ActivateInputPanel | |
on ActivateOutputPanel() | |
ActivatePanelByName(OutputPanelName) | |
end ActivateOutputPanel | |
on GetSelectedInputName() | |
ActivateInputPanel() | |
GetSelectedSourceName() | |
end GetSelectedInputName | |
on GetSelectedOutputName() | |
ActivateOutputPanel() | |
GetSelectedSourceName() | |
end GetSelectedOutputName | |
on SetSelectedInput(inputName) | |
ActivateInputPanel() | |
SetSelectedSource(inputName) | |
end SetSelectedInput | |
on SetSelectedOutput(outputName) | |
ActivateOutputPanel() | |
SetSelectedSource(outputName) | |
end SetSelectedOutput | |
if not EnsureGuiScriptingEnabled() then | |
return | |
end if | |
set systemPreferencesAlreadyRunning to IsSystemPreferencesRunning() | |
tell application "System Preferences" to activate | |
ActivateSoundPreferencePane() | |
-- TODO: save current preference pane | |
set previousInputName to GetSelectedInputName() | |
SetSelectedInput("SoundFlower (2ch)") | |
set previousOutputName to GetSelectedOutputName() | |
SetSelectedOutput("SoundFlower (2ch)") | |
HideSystemPreferences(true) | |
do shell script "/usr/local/bin/RaopX &> /dev/null &" | |
display dialog "RaopX is running" buttons {"Quit"} default button "Quit" | |
do shell script "killall -KILL RaopX &> /dev/null || true" | |
try | |
do shell script "rm /tmp/raopxtmpbuffer" | |
end try | |
SetSelectedOutput(previousOutputName) | |
SetSelectedInput(previousInputName) | |
if not systemPreferencesAlreadyRunning then | |
tell application "System Preferences" to quit | |
else | |
HideSystemPreferences(false) | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment