I've been using BTT for about a month now, so still new to all this. I'm not a programmer, but I like messing around with scripting from time to time. I don't really know what I'm doing.
I'm trying to make my touch bar display the name of the frontmost active window. I'm trying to basically mirror the system menu bar on my touch bar -- then I can hide the menu bar to give me some extra screen space without loosing any of the key info that it provides.
Here's the button as I have it configured now. It doesn't work quite right. It's a "Shell Script / Task Widget" in my Touch Bar.
activeApp=$(lsappinfo info -only name `lsappinfo front` | sed -n 's/^.*"."//p' | sed 's/.$//')
(osascript <<EOF
tell application "BetterTouchTool"
update_touch_bar_widget "01ECFDFA-CED3-496C-B5A6-5901A266B010" text "$activeApp"
refresh_widget "01ECFDFA-CED3-496C-B5A6-5901A266B010"
end tell
EOF
)
I'll give a breakdown of what I was trying to do...
This shell command gets the name of the frontmost application and formats it properly.
lsappinfo info -only name `lsappinfo front` | sed -n 's/^.*"."//p' | sed 's/.$//'
It works when I run it in Terminal. And when I attach this snippet to a BTT Shell Script widget, it works, but it doesn't update quick enough when I change apps. (I have the BTT Touch Bar configured to stay hidden until I press a modifier key, via the advanced Touch Bar setting checkbox "Allow keyboard modifiers to restore a hidden touch bar when they are pressed.") This widget's checkbox "Always run when widget becomes visible" is checked, but it's still too slow.
On to the next part.
I believe this AppleScript code should help the widget react more quickly and responsively. But instead, it breaks the button when I add it to the script. Instead of showing the application name normally, it starts flickering incredibly fast, and then the button vanishes from the touch bar after a moment or two.
tell application "BetterTouchTool"
update_touch_bar_widget "01ECFDFA-CED3-496C-B5A6-5901A266B010" text "$activeApp"
refresh_widget "01ECFDFA-CED3-496C-B5A6-5901A266B010"
end tell
Is there a better way to do this? I know I could run it all in AppleScript instead of Shell. But it seemed like that was even slower.
tell application "System Events"
set frontmostProcess to first process where it is frontmost
set appName to name of frontmostProcess
end tell
return appName
tell application "BetterTouchTool"
update_touch_bar_widget "BDAE1084-0BF5-436F-99D7-1C441AC6CD20" text appName
refresh_widget "BDAE1084-0BF5-436F-99D7-1C441AC6CD20"
end tell
Thanks for any help!