Comments (4)
YOU RULE!!
Thnx so much!
from hammerspoon.
hs.menubar.newWithPriority
hasn't actually worked correctly for quite a while now, and was removed. (It was based on private APIs for setting the menu's position/priority that no longer work.)
However, at the same time that it was removed, support was added for making hs.menubar
s stay in whatever position you ⌘ Command-drag them to. Basically, you need to switch to using hs.menubar.new
, and setting the autosaveName
parameter to some sort of unique identifier for that particular menu (or set it afterwards using the :autosaveName()
method)1. At that point, if you hold ⌘ Command and drag the menu to where you want it, it should stay there across Hammerspoon relaunches/reloads.
If you want to, you can even set the position programmatically, by modifying the preferences where that position is stored:
local menuName = 'My Whatever Menu'
local menuPosition = 500
-- ^ seems to be the distance between the right edge of the menubar, and the center(?) of the menu)
hs.settings.set('NSStatusItem Preferred Position ' .. menuName, menuPosition)
myMenu = hs.menubar.new(true, menuName) -- probably needs to be after that hs.setting.set call
Footnotes
-
If you don't set it, it will default to
Item-0
,Item-1
, etc., which means it could change if you add anotherhs.menubar
instance later.↩
from hammerspoon.
Ok, that seems to be the problem then.
I am REALLY a n00b with coding and HammerSpoon lua...:(
So first of thanks for the response!
Can you help me out with the new code to only show the SSID from the WiFi?!
So can you help me out how to configure this CONFIG I had working for some while:
OLD CODE:
wifiMenu = hs.menubar.newWithPriority(2147483645)
wifiMenu:setTitle(hs.wifi.currentNetwork())
wifiWatcher = nil
function ssidChanged()
local wifiName = hs.wifi.currentNetwork()
if wifiName then
wifiMenu:setTitle(wifiName)
else
wifiMenu:setTitle("Wifi OFF")
end
end
wifiWatcher = hs.wifi.watcher.new(ssidChanged):start()
from hammerspoon.
Most of that looks good. As far as I can tell, the only thing that needs to change is that very first line:
wifiMenu = hs.menubar.new(true, 'Wifi SSID')
-- ^ ^ ^-- autosaveName (makes the menu stay in the same place across Hammerspoon launches)
-- | | This can be whatever you want.
-- | | It just controls the name for the preference where the position is saved.
-- | `-------- Start out showing it in the menubar
-- | (default, but needed to get autosaveName into the right argument)
-- `------------ Use new() instead of newWithPriority()
-- Everything from here on is the same as what you have now:
wifiMenu:setTitle(hs.wifi.currentNetwork())
wifiWatcher = nil
function ssidChanged()
local wifiName = hs.wifi.currentNetwork()
if wifiName then
wifiMenu:setTitle(wifiName)
else
wifiMenu:setTitle("Wifi OFF")
end
end
wifiWatcher = hs.wifi.watcher.new(ssidChanged):start()
The menu will appear at the left end of the menu extras section, but at that point, you should be able to Cmd-drag the menu to wherever you want it and have it stay there.
from hammerspoon.
Related Issues (20)
- hs.autoLaunch call causes application hang if Login Items contain unreachable network devices HOT 2
- TextClipboardHistory has become VERY slow
- hs.eventtap.keyStroke({"cmd"}, "]") work only with double tap HOT 3
- hs.setting.set does not allow values starting with uppercase HOT 6
- On Apple Silicon (M2 Air) audiodevice:balance() returns nil for builtin speakers
- Detect if text cursor is active (in an active text field)
- hs.spaces.allSpaces() error during macOS boot?
- What is the best way to open the console? HOT 2
- error move window to space
- Webview window type
- Websocket clients not getting the message returned by the message handler HOT 2
- How to select non-menu items? HOT 1
- hs.space.watcher always returns "-1"
- hs.application.launchOrFocus(name) -> boolean should have an optional parameter allWindows like the hs.application:activate(allWindows)
- Feature Request: Disable logging for hotkey enable and disable HOT 3
- UTF8/Styledtext and Precomposed Characters
- Feature Request: Portable option to use XDG
- hs.application:selectMenuItem() sometimes selects wrong menu item
- Build Issue - pygments~=2.11.2 distribution was not found HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hammerspoon.