No internet connection
  1. Home
  2. How to

Dim and Muting speakers

By Omar Gonzalez @Omar_Gonzalez7
    2023-03-28 18:43:50.141Z

    Hi,

    I'd like to be able to create two actions that allow me to separately mute and dim my speakers. Dimming would ideally be set to a specific volume level.

    I tried doing this with the "Press Keys" function but soundflow would not allow me to set of any of the macOS function keys. I also didn't see much in the way of finder scripting.
    Is this possible to achieve?

    Solved in post #2, click to view

    Linked from:

    1. Speaker DIm issue
    • 4 replies
    1. Chris Shaw @Chris_Shaw2023-03-28 22:46:26.510Z2023-03-29 14:53:27.766Z

      I'm assuming you're trying to mute and dim the output of your Mac. if you're trying to mute and dim your interface you'd have to look into your interface's software.

      This should dim your system volume (if you change the volume while dimmed, change the volume then un-dim the volume will return to the original volume before dimming)

      //dim percentage below is relative to whatever your current volume is
      // in this case the volume will be 77 percent of the current volume
      const dimPercentage = 77
      function getSystemVolume() {
          return Math.round(+sf.system.execAppleScript({
              script: 'get volume settings'
          })["Result"].split(",")[0].split(":")[1]);
      }
      function dimSystemVolume() {
      
          let newSystemVolume
          if (!globalState.prevSystemVol) globalState.prevSystemVol = getSystemVolume();
          if (!globalState.isSysVolumeDimmed) {
              newSystemVolume = globalState.prevSystemVol * (dimPercentage/100);
              globalState.dimmedVolume = newSystemVolume;
              globalState.isSysVolumeDimmed = true
              log ("Dimmed")
          } else {
              newSystemVolume = globalState.prevSystemVol;
              globalState.isSysVolumeDimmed = false
              delete globalState.prevSystemVol
              log ("Un- Dimmed")
          }
          sf.system.execAppleScript({
              script: `set volume output volume ${Math.round(newSystemVolume)}`
          });
      }
      
      
      dimSystemVolume()
      

      This will toggle the system volume between mute and un-muted:

      function toggleSystemAudioMute() {
          sf.system.execAppleScript({
              script: `set curVolume to get volume settings
      if output muted of curVolume is false then
      	set volume with output muted
      else
      	set volume without output muted
      end if`,
          });
      }
      
      toggleSystemAudioMute()
      ReplySolution
      1. OOmar Gonzalez @Omar_Gonzalez7
          2023-03-29 02:59:13.712Z

          Thanks for the reply Chris. Neither scripts are working. This is the log from the mute script
          28.03.2023 19:57:16.46 [Backend]: Run command: user:ckz8y90wh0000o310s4q3479y:clft3bwr000003y10qi01kuul
          #StreamDeck: deck-button-click -> Mute

          28.03.2023 19:57:16.46 [Backend]: >> Command: Mute [user:ckz8y90wh0000o310s4q3479y:clft3bwr000003y10qi01kuul]
          << Command: Mute [user:ckz8y90wh0000o310s4q3479y:clft3bwr000003y10qi01kuul]

          And this is the log for when I run Dim
          28.03.2023 19:58:58.93 [Backend]: Run command: user:ckz8y90wh0000o310s4q3479y:clft3c2t400013y10q04kgobt
          #StreamDeck: deck-button-click -> Dim

          28.03.2023 19:58:58.93 [Backend]: >> Command: Dim [user:ckz8y90wh0000o310s4q3479y:clft3c2t400013y10q04kgobt]
          JavaScript error with InnerException: null
          !! Command Error: Dim [user:ckz8y90wh0000o310s4q3479y:clft3c2t400013y10q04kgobt]:
          ReferenceError: getSystemVolume is not defined
          (Dim line 4)

          << Command: Dim [user:ckz8y90wh0000o310s4q3479y:clft3c2t400013y10q04kgobt]

          1. Sorry about that Omar,
            I didn't properly copy/paste the scripts.

            I've edited and checked the code above. It should work now.
            //CS//

            1. OOmar Gonzalez @Omar_Gonzalez7
                2023-03-29 15:23:07.689Z

                That seems to be working now. Thank you!