Open Mortennn opened 5 years ago
After seeing how Dozer hides icons using this:
static let hide: CGFloat = 10_000
I suppose the way to go might be some kind of AppleScript.
Also would like to hide icons programmatically
This might be useful: https://github.com/shergin/NSStatusBar-MISSINGOrder
This might be useful: https://github.com/shergin/NSStatusBar-MISSINGOrder
@AndrewMast those do not respond (macOS 10.14), so that code is obsolete :(
[self respondsToSelector:statusItemWithLengthWithPrioritySelector] &&
[self respondsToSelector:insertStatusItemWithPrioritySelector]
I noticed some keys in the plist preference file for apps:
NSStatusItem Preferred Position Item-0
What about reading and writing these keys in app preferences? I believe this is what macOS does when icons are rearranged using cmd+drag.
So I am thinking that even though all positions are "preferred", if Dozer manages all of these positions for all menu bar icons, then they should be granted their desired position without exception. Right?
We could read the keys to find out the preferred position of an icon, which after Dozer managed them all would be the actual position.
I have not checked how macOS refreshes the positions during cmd+drag, but it most certainly does not require app to restart themselves.
Searching GitHub for that, I found this shell script https://github.com/DaFuqtor/barhide that writes a key to an app preferences plist to hide menu bar icons.
NSStatusItem Visible Item-0
SystemUIServer
to hide Notification Centre icon (or Airport, or Bluetooth but those can be hidden using the normal user interface).Probably not good enough to be the way Dozer hides/shows icons.
What do you think @Mortennn @aonez ?
Great research!
So I am thinking that even though all positions are "preferred", if Dozer manages all of these positions for all menu bar icons, then they should be granted their desired position without exception. Right?
This is actually a pretty clever thought. Could work. We would probably also need to figure out which process updates the menu bar icons after we have updated the plists.
As you say, thought B requires restart, so it is sadly not an option.
As a side note, Bartender requires accessibility access, so we might need to look in that direction.
Thought I'd start a list of what we may need to do:
...there are probably more!
Bartender showed me this in Big Sur:
How do they do it?
From what it looks like, it would appear that Bartender is indeed using some form of @gingerbeardman's "Thought A" where it manages the values of each app's NSStatusItem Preferred Position Item-n
.
Prior to using Bartender to make any adjustments to an app I use which has 3 seperate NSStatusItem
's, the value for each item was:
NSStatusItem Preferred Position Item-0
= 435.76
NSStatusItem Preferred Position Item-1
= 447
NSStatusItem Preferred Position Item-2
= 474.5
After changing the app's visibility setting in Bartender from the default "Show" to the new value of "Hide", those values were each immediately changed to :
NSStatusItem Preferred Position Item-0
= 20435.76
NSStatusItem Preferred Position Item-1
= 20447
NSStatusItem Preferred Position Item-2
= 20474.5
(increased by 20000)
So to "hide" the icons, it looks like they are really just moving them so far to the left on the menubar that they can't possibly be in view.
@dmattera How do those positions change if you rearrange those menu bar items? Both using Bartender and not would be useful to know.
Does anyone know how to move status bar icons programmatically?