jaredks / rumps

Ridiculously Uncomplicated macOS Python Statusbar apps
BSD 3-Clause "New" or "Revised" License
3.06k stars 177 forks source link

rumps App gets hidden if title is too long #198

Open vladoski opened 1 year ago

vladoski commented 1 year ago

I'm trying to use rumps to make a simple RSS feed title viewer in my macOS status bar, displaying the RSS article title on the status bar app title. Sometimes, the title is too big for my status bar and the app won't be visible anymore. I've tried to tinker with rumps to see if there's a way to know beforehand how much free space there is on the status bar but I couldn't come up with a solution.

Is there a way to do it? I'd be happy even if I'd have to make a big mess with Foundation/AppKit wrappers.

SKaplanOfficial commented 1 year ago

I don't think you can detect how much space is available, unfortunately, but you could detect whether the menu bar item is visible and then adjust the title accordingly. Since hiding is different from forced removal, you have to check the item's window visibility. To do that, you can use a private API to check the window occlusion state:

app._nsapp.nsstatusitem._window().occlusionState()

This will return 8194 if the item is displayed and 8192 if it's not. If it's not displayed, you can update the title to something shorter.

stefanbuchauer commented 2 weeks ago

how about adding a feature to scroll the title text back and forth automatically? i try do implement this actually in my script, but somehow the text is moved one line up...