dippnerd / airfoil-speakers-applescript

AppleScripts I use with the Airfoil app for macOS to toggle my AirPlay speakers
2 stars 0 forks source link

Can't change volume #1

Open ghost opened 5 years ago

ghost commented 5 years ago

Hi dippnerd,

I have an issue where I can't change the volume of my Airplay speakers when in a specific state. I'm hoping you could help? My applescript-fu is ..limited. I suspect that someone with intermediate knowledge can help me out relatively easy.

So, I have two airplay speakers "Airport 1 Living Room" and "Airport 2 Kitchen". I mostly play music to them simultaneously using Airfoil. I'm using Bettertouchtool to change the volume of those speakers (a hotkey shift-volume up/down triggering an Applescript). This works well every time 👍

Screenshot 2019-09-13 at 10 50 44

When one of the Airports is offline (meaning not on the network on purpose - for reasons outside of this scope), my script doesn't change the volume anymore for the one that ìs online.

My applescript must be lacking somewhere. I tried different things but I don't what I'm doing 👎

Here's my script for volume up:

tell application "Airfoil"
    set LivingSpeaker to first speaker whose name is "Airport 1 Living Room"
    set KitchenSpeaker to first speaker whose name is "Airport 2 Kitchen"

    set LivingVolume to get volume of LivingSpeaker
    set KitchenVolume to get volume of KitchenSpeaker

    set (volume of LivingSpeaker) to (LivingVolume - 0.03)
    set (volume of KitchenSpeaker) to (KitchenVolume - 0.03)
end tell

Hope you can help! Cheers

dippnerd commented 5 years ago

Is any one particular device more likely to stop working than the other? If so, just group those actions together and put them last, it should mean the first one still gets run and the second should just get ignored if it didn't run properly. Something like this:

tell application "Airfoil"
    set LivingSpeaker to first speaker whose name is "Airport 1 Living Room"
    set LivingVolume to get volume of LivingSpeaker
    set (volume of LivingSpeaker) to (LivingVolume - 0.03)

    set KitchenSpeaker to first speaker whose name is "Airport 2 Kitchen"
    set KitchenVolume to get volume of KitchenSpeaker
    set (volume of KitchenSpeaker) to (KitchenVolume - 0.03)
end tell
ghost commented 5 years ago

That is helpful! Thank you.

I do wish I could write a script that would still work, independent of either speaker being off the network. I was hoping some kind of if-then statement would help? I tried something like 'if x is connected, then set volume for x, if else goto y', but, again, I don't really know what I'm doing and it didn't work as I hoped.

Anyway, for now I will implement your work around; I do indeed have mostly one particular airport going on/off. Btw, the on/off of that airport is desired behaviour. It's due to power saving: it's part of all home-cinema devices grouped on one outlet that I toggle on/off with a smart outlet.

On Fri, 13 Sep 2019 at 16:08, Aaron Dippner notifications@github.com wrote:

Is any one particular device more likely to stop working than the other? If so, just group those actions together and put them last, it should mean the first one still gets run and the second should just get ignored if it didn't run properly. Something like this:

tell application "Airfoil" set LivingSpeaker to first speaker whose name is "Airport 1 Living Room" set LivingVolume to get volume of LivingSpeaker set (volume of LivingSpeaker) to (LivingVolume - 0.03)

set KitchenSpeaker to first speaker whose name is "Airport 2 Kitchen" set KitchenVolume to get volume of KitchenSpeaker set (volume of KitchenSpeaker) to (KitchenVolume - 0.03) end tell

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dippnerd/airfoil-speakers-applescript/issues/1?email_source=notifications&email_token=AFQ3G7GKONHMGZ2FAMSS2ELQJONGPA5CNFSM4IWNU2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6VECQQ#issuecomment-531251522, or mute the thread https://github.com/notifications/unsubscribe-auth/AFQ3G7GR47GPYXB4HGGHXQ3QJONGPANCNFSM4IWNU2OQ .

ghost commented 5 years ago

I found a solution that works for me: the "Airfoil Volume Up/Down" scripts from here https://github.com/dbyler/applescript-misc

Good day