Could need some help. One volume control.

Hello All,
I have always been a little confused with the different volume controls in an app vs. system volume. So when usin spotify you can set volume in the app independently from the system volume. And so, to get max. volume you need to change the volume in two places.

I thought it would be interesting to try to create one volume control to control both.
I have nicknamed it TOASTR-V (The One Amazing Slider To Rule - Volume) :wink:
But... I can't get it to work. I am no developer/programmer by any means so hoping you can help me out.

What I am trying to do:

Get current setting for system volume and spotify volume (if running)
set "Custom Apple Script Slider Widget" initial value to the average of these value
When the slider is used calculate the new values and apply to both the spoitfy volume and system volume.

Looks simple enough but it doesn't work. My feeling is that the variables don't get from the initial run of the widget to the applescript when sliding the widget.

My current code:

to get initial values and set slider:

if application "Spotify" is running then
set inisysvol to output volume of (get volume settings)
tell application "Spotify"
set inispotifyvol to get sound volume
end tell
set inivol to (((inispotifyvol + inisysvol) / 2) / 100)
set inivol to output volume of (get volume settings)
end if

return inivol

When moving the slider:

on bttWidgetSliderMoved(sliderValue)

if (sliderValue * 100) ≥ inivol then

set newsysvol to (inisysvol + ((((sliderValue * 100) - inivol) / (100 - inivol)) * (100 - inisysvol)))
set newspotifyvol to (inispotifyvol + ((((sliderValue * 100) - inivol) / (100 - inivol)) * (100 - inispotifyvol)))

else if (sliderValue * 100) < inivol then

set newsysvol to (inisysvol - ((inivol - (sliderValue * 100)) / inivol) * (inisysvol))
set newspotifyvol to (inispotifyvol - ((inivol - (sliderValue * 100)) / inivol) * (inispotifyvol))

end if

if application "Spotify" is running then

tell application "Spotify"
set sound volume to newspotifyvol
end tell

set volume output volume newsysvol


set volume output volume newsysvol

end if

end bttWidgetSliderMoved

Any suggestions are welcome!

Screenshots (optional)
You can just drag or paste your screenshots here.

Just quietly moving this to the #discussion thread... I'm sure you'd find more help there!
Sorry for any inconvenience.

Please keep the preset market clean ~