Git Product home page Git Product logo

Comments (4)

JasonXGaming avatar JasonXGaming commented on June 9, 2024 1

YOU RULE!!

Thnx so much!

from hammerspoon.

Rhys-T avatar Rhys-T commented on June 9, 2024

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.menubars 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

  1. If you don't set it, it will default to Item-0, Item-1, etc., which means it could change if you add another hs.menubar instance later.

from hammerspoon.

JasonXGaming avatar JasonXGaming commented on June 9, 2024

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.

Rhys-T avatar Rhys-T commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.