display custom overlay from shell script output

I use cmus to listen to music, I have added vol up/down buttons to my touchbar using a shell script:

/usr/local/bin/cmus-remote -C 'vol +10%'

I can show a notification of the new volume like this:

volume=$(/usr/local/bin/cmus-remote -C 'format_print %{lvolume}')
/usr/bin/osascript -e "display notification \"Volume: ${volume}\" with title \"CMUS\""

But this notification is permanent, I'd ideally like to show an overlay similar to the built-in OSX volume overlay. I saw BTT has a Show HUD Overlay which allows dynamic scripting, but I can't work out how to use the output of a shell script as a dynamic variable, is this possible? Or any other workaround to get a quick ~500ms popup showing the output of a shell script?

Thanks in advance,


If you run the terminal command in BTT, the easiest way is to use the BTTLastTerminalCommandResult variable in the hud action:

Thanks for the suggestion, unfortunately I have another script that runs every second to display the current artist/album/album art and time elapsed from CMUS, as well as a few others, and most of the time the last command result is not the volume script.

For anyone else with this problem, I changed from using the "execute shell script" to "execute terminal command (synchronous, blocking)" which now returns the correct value.

Thanks a lot!

Alternatively you can also directly trigger hud actions (like any other BTT action) from Apple Script. However with current versions the escaping can be tricky in Apple Script. With the next alpha you can do it without much escaping:

Old/current version:

tell application "BetterTouchTool"
	trigger_action "{
  BTTPredefinedActionType: 254,
  BTTHUDActionConfiguration: '{\\\"BTTActionHUDBlur\\\":true,\\\"BTTActionHUDTitle\\\":\\\"Hello\\\", \\\"BTTActionHUDDetail\\\":\\\"World\\\",\\\"BTTActionHUDDuration\\\":0.5,\\\"BTTActionHUDWidth\\\":220,\\\"BTTActionHUDHeight\\\":220}'}"
end tell

Next upcoming version:

tell application "BetterTouchTool" to trigger_action "{
  BTTPredefinedActionType: 254,
  BTTHUDActionConfiguration: {
	BTTActionHUDTitle: 'hello',
	BTTActionHUDDetail: 'world',
	BTTActionHUDBlur: true,
	BTTActionHUDWidth: 200,
	BTTActionHUDHeight: 200,
	BTTActionHUDDuration: 0.5
1 Like

Nice, much cleaner! Thanks for all your work on this app, I think the user's imagination is the only real limiting factor!

1 Like