Sound balance keeps changing on High Sierra and Mojave
So i found a solution on Reddit with the AppleScript but this did not work completely form me because it was throwing errors sometime:
&quot;System Events got an error: Can’t get tab group 1 of window 1 of process \&quot;System Preferences\&quot;. Invalid index.&quot; number -1719 from tab group 1 of window 1 of process &quot;System Preferences&quot;
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 &quot;System Preferences&quot;
     activate
     reveal anchor &quot;output&quot; of pane id &quot;com.apple.preference.sound&quot;
end tell
tell application &quot;System Events&quot;
     tell slider 1 of group 1 of tab group 1 of window 1 of process &quot;System Preferences&quot;
          set value to 0.5
     end tell
end tell
tell application &quot;System Preferences&quot;
     quit
end tell

Working code
I made some changes to the code:
tell application &quot;System Preferences&quot;
    activate
    reveal anchor &quot;output&quot; of pane id &quot;com.apple.preference.sound&quot;
end tell

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

tell application &quot;System Preferences&quot;
    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 &gt;/dev/null 2&gt;&amp;1

And on Mojave, you need to give the first time permissions to Cron to access Accessibility (under Security &amp; 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 -&gt; Default Results -&gt; 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.