swiftbar / SwiftBar

Powerful macOS menu bar customization tool
https://swiftbar.app
MIT License
2.95k stars 92 forks source link

Lock/Unlcok event notification #346

Closed futurist closed 1 year ago

futurist commented 2 years ago

Program want to get notification about system status, like lock/unlocked, like below:

https://stackoverflow.com/questions/35932501/check-device-is-locked-or-unlocked

I have a script running related to screen unlocked, and stop running when screen locked, need this type of notification.

Can swiftbar add this support?

melonamin commented 2 years ago

I've been thinking about adding "Triggers" to SiwftBar, where Trigger is something that kicks off plugin refresh. In this sense Locked\Unlocked is a kind of Trigger.

Something like this will work?

futurist commented 2 years ago

Trigger looks good. Maybe some other form like linux init script does: https://old.calculate-linux.org/main/en/initscripts https://gist.github.com/drmalex07/298ab26c06ecf401f66c

That way trigger/event can send stop/start etc. messages, or directly send the events to scripts?

melonamin commented 2 years ago

directly send the events to scripts

I don't see how it is doable. i'm goinng to handle it the same as Sleep\Wake cycle by setting an environment variable. If and when we implement triggers, it will work as follows:

Sepparetly from that, we can implement "Don't refresh this script when locked" option on per plugin basis, which sounds like what you wanted originally.