Changing Touch Bar Button Text (via Python shell script)

Hi all,

This is my first post in the community- I'm glad to be here.

I'm working on a Python shell script that scrapes data from the web and prints it into a long line text onto a touch bar button. I'm using osascript in Python to run embedded Applescript within the shell script.

My main goal right now is to get the text to automatically scroll from right to left, like a news ticker. My solution is to have the string shift/wrap around itself, while Python prints/replaces the new text on a loop.

Something like "Button Text" -> Print() -> "utton Text B" -> Print() -> "tton Text Bu" -> Print(), and so on.

The issue I'm encountering with the above solution is as follows:

After using Python's "print()" function, the button text is not cleared when "print()" is run again, so the button's text value cannot be updated/replaced. The function seems to add a new line to the button text instead (I'm assuming this because the initially printed line of text is no longer vertically center in the button).

How can I programatically, in Python or Applescript, clear the button text so the touch bar button text can be completely replaced?

Any feedback or support would be much appreciated.

Could you use a widget instead of a button? Widgets let you run AppleScript and output the result to the text of the button. I don’t have knowledge of python, but if you can pull in the text via applescript, it'll update the button.

I'm not sure if it's the default "now playing" widget or if it was in another preset (goldenChaos, aquatouch, or minimalist), but I think I saw a widget that scrolled song titles at some point. Check those out and see if they give you some ideas.

Thanks Bobj.

Sorry, widget is actually what I meant. I was referring to the look of the "button" on the tool bar generally.

The reason why I'm using Python (Run Shell Script And Show Return Value) is because I need parser dependencies like Beautiful Soup. I've gotten the text to show on the widget and even to scroll using a loop and the update_trigger, but I'm still working on a smoother implementation that would play nice with the "execute every x seconds" aspect of the widget.

Will share my work on this forum when it's ready.

Anyway, thanks for your help. I'll look for the now playing widget for more ideas.