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

Speaker DIm issue

By Omar Gonzalez @Omar_Gonzalez7
    2024-09-10 04:39:21.827Z

    Title

    Speaker DIm issue

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

    This is supposed to dim my volume by 80%

    Are you seeing an error?

    Soundflow error is telling me theres an issue with line 6. It specifically says:

    !! Command Error: Speakers_Dim [user:clvbjeg2i0007e610y1bui0sa:clvbjfxpa000ae6107exwc1we]:
    TypeError: Object has no method 'split'
    (Speakers_Dim line 6)

    << Command: Speakers_Dim [user:clvbjeg2i0007e610y1bui0sa:clvbjfxpa000ae6107exwc1we]

    What happens when you run this script?

    Script is tied to a stream deck button. I press the button and an error immediately comes up.

    How were you running this script?

    I used a Stream Deck button

    How important is this issue to you?

    2

    Details

    {
        "inputExpected": "This is supposed to dim my volume by 80%",
        "inputIsError": true,
        "inputError": "Soundflow error is telling me theres an issue with line 6. It specifically says: \n\n!! Command Error: Speakers_Dim [user:clvbjeg2i0007e610y1bui0sa:clvbjfxpa000ae6107exwc1we]:\nTypeError: Object has no method 'split'\n(Speakers_Dim line 6) \n\n<< Command: Speakers_Dim [user:clvbjeg2i0007e610y1bui0sa:clvbjfxpa000ae6107exwc1we]",
        "inputWhatHappens": "Script is tied to a stream deck button. I press the button and an error immediately comes up.",
        "inputHowRun": {
            "key": "-MpfwmPg-2Sb-HxHQAff",
            "title": "I used a Stream Deck button"
        },
        "inputImportance": 2,
        "inputTitle": "Speaker DIm issue"
    }

    Source

    //dim percentage below is relative to whatever your current volume is
    // in this case the volume will be 80 percent of the current volume
    const dimPercentage = 80
    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()
    

    Links

    User UID: aMkTBTHB3he77TafFWFI244Jm9j1

    Feedback Key: sffeedback:aMkTBTHB3he77TafFWFI244Jm9j1:-O6PDeChkn8IxGQkMIi_

    Feedback ZIP: TvuLRoWvEDq6YsI2jPPLLjpUKSq1LIEpSXx8V4OPTF8eYgzq+LmUfeh6pj0pq9faSllwnj1RrfROl7YgbzrYdY0XiXFe7Ia5zKsBzbZwGQSGacJaONVcRSnAYJa0QzCmiwfk03oWVkBnhBteIN3Ls2CZfQcnvgTfeDuoVR/oDlgaQLhKe2KbPiBfwceM9VsfkrRMmw7Z8CEDg2zV9MkIQ0uPi0Hbraw6I6NOVb3GWkY3QCxRe3j7M33Kcd1DsYfkWGE2qxGTOU591EGHVz0wGfVm0CASmvwsAesXTv963krJerekmRp/baOGCuYl148LkJ4MvreUXVT10ljjX6mDVMjr2omfogvFNRw2u5tP3jg=

    Solved in post #3, click to view
    • 3 replies
    1. O
      Omar Gonzalez @Omar_Gonzalez7
        2024-09-10 04:44:01.757Z

        This script was previously written for me by Chris Shaw. Their Dim script still works fine
        Dim and Muting speakers

        1. Chad Wahlbrink @Chad2024-09-10 14:39:30.566Z

          Hey @Omar_Gonzalez7,

          The sf.system.execAppleScript command was tweaked in SoundFlow 5.8. In this instance, you will need to add implementation:"OSAScript"affter line 6.

          Try this code out:

          //dim percentage below is relative to whatever your current volume is
          // in this case the volume will be 80 percent of the current volume
          const dimPercentage = 80
          function getSystemVolume() {
              return Math.round(+sf.system.execAppleScript({
                  script: 'get volume settings',
                  implementation:"OSAScript"
              })["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()
          
          Reply1 LikeSolution
          1. OOmar Gonzalez @Omar_Gonzalez7
              2024-09-10 16:21:28.484Z

              That worked great. Thanks!!