No internet connection
  1. Home
  2. Macro and Script Help

Mute/Un Mute Speakers and log

By Omar Gonzalez @Omar_Gonzalez7
    2023-04-07 20:45:03.118Z

    Title

    Mute/Un Mute Speakers and log

    What do you expect to happen when you run the script/macro?

    This script mutes and un mutes my speakers. Script works great!

    Are you seeing an error?

    What happens when you run this script?

    My speakers get muted and un muted. I would like to add a log function that tells me if I muted or un muted the speakeres

    How were you running this script?

    I used a Stream Deck button

    How important is this issue to you?

    3

    Details

    {
        "inputExpected": "This script mutes and un mutes my speakers. Script works great!",
        "inputIsError": false,
        "inputWhatHappens": "My speakers get muted and un muted. I would like to add a log function that tells me if I muted or un muted the speakeres",
        "inputHowRun": {
            "key": "-MpfwmPg-2Sb-HxHQAff",
            "title": "I used a Stream Deck button"
        },
        "inputImportance": 3,
        "inputTitle": "Mute/Un Mute Speakers and log"
    }

    Source

    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()
    
    

    Links

    User UID: aMkTBTHB3he77TafFWFI244Jm9j1

    Feedback Key: sffeedback:aMkTBTHB3he77TafFWFI244Jm9j1:-NSSSmYZqoxbfqp4WQbL

    Feedback ZIP

    Solved in post #5, click to view
    • 5 replies
    1. O
      Omar Gonzalez @Omar_Gonzalez7
        2023-04-07 20:46:48.826Z

        This is a similar script that someone here wrote for me that dims my speakers. Notice that it has a log function. I would like to add that to the mute script

        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)}`
        });
        
        1. Brenden @nednednerb
            2023-04-08 18:49:37.001Z

            I cannot speak for how to format the AppleScript; that's not a SoundFlow thing.

            Why don't you use the script you shared? Does it not work? If it works, why adapt the AppleScript?
            https://stackoverflow.com/questions/13653358/how-to-log-objects-to-a-console-with-applescript
            The above post says "AppleScript does not make it easy" to log to a console.

            SF can run other kinds of script, but I think that's most useful for Apple OS inner working-centric functions, rather than to log something for SF console.

            I could see you making additional variables in SF based on whether a totally new AppleScript actually runs. But it seems to be a back and forth between AppleScript Code and SF code JUST for a log message. Hence, again, why don't you use the "similar script"? If it doesn't work, it seems like it almost might. It "looks" well written at first glance.

            1. OOmar Gonzalez @Omar_Gonzalez7
                2023-04-08 20:13:39.082Z

                The mute script works fine. The dim script gives me a sound flow notification that say's "dimmed" and "un-dimmed" when used respectively. I want to add that functionality to the mute script because it's nice to see, and I know its possible to have since the dim script has it

            2. In reply toOmar_Gonzalez7:

              @Omar_Gonzalez7, here you go!

              function toggleSystemAudioMute() {
                  const state = sf.system.execAppleScript({
                      script: `set curVolume to get volume settings
              if output muted of curVolume is false then
              	set volume with output muted
                  return "System Audio Muted"
              else
              	set volume without output muted
                  return "System Audio Unmuted"
              end if`,
                  }).result;
              
                  return { state };
              }
              
              log(toggleSystemAudioMute().state);
              
              ReplySolution
              1. OOmar Gonzalez @Omar_Gonzalez7
                  2023-04-09 06:39:05.960Z

                  Thank you Raphael!