Script no longer working

I have this Stream Deck button which has been working fine for ages but now the script is not behaving as it used to and I don't know why.

I can copy the script and run it from Terminal and it works as I expect. The BTT version seems to skip the sed command. I tried qualifying it with /usr/bin but it still doesn't work.

[
  {
    "BTTActionCategory" : 0,
    "BTTLastUpdatedAt" : 1733795887.7939949,
    "BTTTriggerType" : 730,
    "BTTTriggerTypeDescriptionReadOnly" : "Shell Script \/ Task Widget",
    "BTTTriggerTypeDescription" : "Battery percentage",
    "BTTTriggerClass" : "BTTTriggerTypeStreamDeck",
    "BTTUUID" : "28FFEF74-3E9C-4222-AA8C-DF6438289A3F",
    "BTTPredefinedActionType" : 366,
    "BTTPredefinedActionName" : "Empty Placeholder",
    "BTTEnabled" : 1,
    "BTTEnabled2" : 1,
    "BTTOrder" : 1,
    "BTTMergeIntoTouchBarGroups" : 0,
    "BTTAdditionalActions" : [
      {
        "BTTActionCategory" : 0,
        "BTTLastUpdatedAt" : 1723852731.1336079,
        "BTTTriggerParentUUID" : "28FFEF74-3E9C-4222-AA8C-DF6438289A3F",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeStreamDeck",
        "BTTUUID" : "B1FF2234-29B1-4AEF-A35B-500DB343FF01",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTOrder" : 228,
        "BTTMergeIntoTouchBarGroups" : 0
      }
    ],
    "BTTStreamDeckButtonName" : "Battery percentage",
    "BTTTriggerConfig" : {
      "BTTScriptRegex" : "(8|9|10)\\d%",
      "BTTStreamDeckCornerRadius" : 12,
      "BTTStreamDeckDisplayOrder" : 0,
      "BTTStreamDeckSFSymbolName" : "battery.75percent",
      "BTTStreamDeckAlternateAttributedTitle" : "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2820\n\\cocoatextscaling0\\cocoaplatform0{\\fonttbl\\f0\\fnil\\fcharset0 B612Mono-Regular;}\n{\\colortbl;\\red255\\green255\\blue255;\\red141\\green224\\blue72;}\n{\\*\\expandedcolortbl;;\\cssrgb\\c61176\\c88627\\c35294;}\n\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\pardirnatural\\qc\\partightenfactor0\n\n\\f0\\fs48 \\cf2 Shell}",
      "BTTStreamDeckAlternateIconColor1" : "156.000006, 226.000002, 90.000002, 255.000000",
      "BTTStreamDeckAlternateIconColor2" : "156.000006, 226.000002, 90.000002, 255.000000",
      "BTTStreamDeckIconColor3" : "255.000000, 192.000004, 114.000001, 255.000000",
      "BTTScriptSettings" : {
        "BTTShellScriptString" : "pmset -g batt | grep 'InternalBattery' | sed -E -e 's\/.+\\)\\t([0-9]{1,3}%).+\/\\1\/'",
        "BTTShellScriptDontTrimWhitepsace" : 0,
        "BTTShellScriptConfig" : "\/bin\/zsh:::-c:::-:::",
        "BTTShellScriptEnvironmentVars" : ""
      },
      "BTTStreamDeckAlternateIconColor3" : "156.000006, 226.000002, 90.000002, 255.000000",
      "BTTStreamDeckAlternateTextOffsetY" : -16,
      "BTTStreamDeckAlternateSFSymbolStyle" : 2,
      "BTTStreamDeckImageOffsetY" : 24,
      "BTTScriptNeverUpdateTitleBasedOnScriptOutput" : 0,
      "BTTStreamDeckIconColor1" : "255.000000, 192.000004, 114.000001, 255.000000",
      "BTTStreamDeckMainTab" : 3,
      "BTTStreamDeckAlternateCornerRadius" : 12,
      "BTTStreamDeckAlternateBackgroundColor" : "0.000000, 0.000000, 0.000000, 255.000000",
      "BTTStreamDeckTextOffsetY" : -16,
      "BTTStreamDeckAppearanceTab" : 1,
      "BTTStreamDeckBackgroundColor" : "0.000000, 0.000000, 0.000000, 255.000000",
      "BTTScriptUpdateInterval" : 60,
      "BTTStreamDeckUseFixedRowCol" : 0,
      "BTTStreamDeckTextOffsetX" : 0,
      "BTTStreamDeckAlternateIconType" : 2,
      "BTTStreamDeckImageOffsetX" : 0,
      "BTTStreamDeckImageHeight" : 24,
      "BTTStreamDeckAttributedTitle" : "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2820\n\\cocoatextscaling0\\cocoaplatform0{\\fonttbl\\f0\\fnil\\fcharset0 B612Mono-Regular;}\n{\\colortbl;\\red255\\green255\\blue255;\\red255\\green255\\blue255;}\n{\\*\\expandedcolortbl;;\\csgray\\c100000;}\n\\pard\\tx560\\tx1120\\tx1680\\tx2240\\tx2800\\tx3360\\tx3920\\tx4480\\tx5040\\tx5600\\tx6160\\tx6720\\pardirnatural\\qc\\partightenfactor0\n\n\\f0\\fs48 \\cf2 Shell}",
      "BTTStreamDeckAlternateImageOffsetX" : 0,
      "BTTStreamDeckAlternateImageHeight" : 24,
      "BTTStreamDeckIconColor2" : "255.000000, 192.000004, 114.000001, 255.000000",
      "BTTStreamDeckIconType" : 2,
      "BTTStreamDeckAlternateImageOffsetY" : 24,
      "BTTStreamDeckSFSymbolStyle" : 2,
      "BTTStreamDeckResizeImage" : 1,
      "BTTStreamDeckFixedRow" : {
        "BTTStreamDeckFixedCol" : "1",
        "BTTStreamDeckFixedRow" : "3"
      },
      "BTTStreamDeckAlternateSFSymbolName" : "battery.100percent"
    }
  }
]

From Terminal, it outputs 79%. From BTT, it outputs -InternalBattery-0 (id=35651683) 79%; AC attached; not charging present: true.

did you maybe upgrade your system? I don’t think there has been a change in BTT.

Does the script return any error when run in BTT?
It looks like this on macOS 15.1.1 for me:

Maybe you can try just calling sed and see whether any error is returned in that case

I'm on Sequoia 15.1.1 which was released on 19 November, and I checked my uptime is at 17 days. I only noticed this problem in the last day or so.

I see no error in BTT...

I ran the command in Terminal as closely as I know to how BTT would run it.

/bin/zsh -c "pmset -g batt | grep 'InternalBattery' | sed -E -e 's/.+\)\t([0-9]{1,3}%).+/\1/'" and that just returns the 79% as the BTT version always used to.

BTT doesn't have your environment variables - possibly try using the full path to every tool
/bin/zsh -c "/usr/bin/pmset -g batt | /usr/bin/grep 'InternalBattery' | /usr/bin/sed -E -e 's/.+)\t([0-9]{1,3}%).+/\1/'"

But also try just "sed" to see whether it outputs some error in case it can't find it

Or could it be some encoding issue that causes sed to fail? Did anything about your language settings change?

It doesn't appear to be sed...

And the output from the original seems to show the grep is working, as it does output the correct line.

The implication is something in the environment is affecting how sed processes text. Weird.

I tried qualifying all commands to /usr/bin which is where they come from in Terminal.

I've removed the sed in Terminal and compared the output and it appears the same as the untranslated one in BTT.

could you try to delete the item and paste it again from your json above? Just to be sure there is no weird database issue

Did that and it still does the same.

Very strange, maybe some whitespace or something like that has changed for some reason?

Does

pmset -g batt | grep -o '[0-9]\{1,3\}%'

work better?

(not sure whether there are every any other battery percentages apart from the internal battery)

That works fine from Terminal but in BTT produces no output. Bizarre.

maybe let's try to convert to utf8 and output an error:

pmset -g batt 2>/dev/null | iconv -f UTF-8 -t UTF-8//IGNORE | grep -Eo '[0-9]{1,3}%' || echo "Battery percentage not found"

Interesting. In Terminal gives 79% and in BTT gives Battery percentage not found.

I have done some more testing.

This works (as in, it returns a matching value 9%).

pmset -g batt | /usr/bin/grep -Eo '[0-9]%' || echo "Battery percentage not found"

This returns the error phrase.

pmset -g batt | /usr/bin/grep -Eo '[0-9]{1,3}%' || echo "Battery percentage not found"

Which tells me that either grep is not acting on the -E (nor sed on it's in my version) or more likely something is being mangled, probably with the { } that grep never gets them intact.

very strange! (especially because it's working fine here)
I have no idea what could cause this :-/

Could you try copying the output of pmset -g batt from BetterTouchTool and put it into eg View non-printable unicode characters to check whether there are any invisible characters or something like that breaking the parsing?

Here's what it says:

Copied from Terminal it is identical.

Given the apparent issue with { } I realised there is an effective workaround...

pmset -g batt | grep -Eo '[0-9]+%'

So I have a working button again, but I sure would love to know why it isn't coping with the { }.