3

i have a problem that every time when i reconnected my Bose QC35 II the sound balance was to the right instead of balanced in the middle.

4

So i found a solution on Reddit with the AppleScript but this did not work completely form me because it was throwing errors sometime: "System Events got an error: Can’t get tab group 1 of window 1 of process \"System Preferences\". Invalid index." number -1719 from tab group 1 of window 1 of process "System Preferences"

original source of the code: https://www.reddit.com/r/apple/comments/34qmn0/is_there_a_shortcut_or_command_to_switch_the_lr/

Original code:

tell application "System Preferences"
     activate
     reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events"
     tell slider 1 of group 1 of tab group 1 of window 1 of process "System Preferences"
          set value to 0.5
     end tell
end tell
tell application "System Preferences"
     quit
end tell

Working code

I made some changes to the code:

tell application "System Preferences"
    activate
    reveal anchor "output" of pane id "com.apple.preference.sound"
end tell

tell application "System Events"
    tell application process "System Preferences"
        repeat until exists tab group 1 of window "Sound"
        end repeat
        tell slider 1 of group 1 of tab group 1 of window "Sound"
            set value to 0.5
        end tell

    end tell
end tell

tell application "System Preferences"
    quit
end tell

i saved my code in ~/Applications/FixSoundBalance.applescript

Cronjob way

And made a crontab crontab -e with the value:

*/5 * * * * /usr/bin/osascript ~/Applications/FixSoundBalance.applescript >/dev/null 2>&1

And on Mojave, you need to give the first time permissions to Cron to access Accessibility (under Security & Privacy, tab privacy), after that, it works fine.

Alfred way

When you use the alfredapp https://www.alfredapp.com/, you can set the under Features -> Default Results -> Extras the checkbox AppleScripts then when you search for Fix... you get the script as result and you can run it directly. Then you do not need to set a cronjob.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .