Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get AnyBar status as open/closed? #54

Closed
KyleKing opened this issue May 28, 2016 · 3 comments
Closed

Get AnyBar status as open/closed? #54

KyleKing opened this issue May 28, 2016 · 3 comments

Comments

@KyleKing
Copy link

Thanks for making this. I'm using AnyBar to show the status of some of my Hammerspoon functions [Lua for mac automation], but I'm having trouble identifying when AnyBar is open or closed. I end up launching duplicate processes or not having a process open. How does everyone else deal with those issues?

But in trying to write my question I think I found a couple of ways to solve this:

# A port known to be open returns a line of text
$ sudo nmap -sU -p 1740 $(ipconfig getifaddr en0) | grep open
1740/udp *open*|filtered encore

# While a closed port returns no text
$ sudo nmap -sU -p 9999 $(ipconfig getifaddr en0) | grep open

But this method can be prone to false positives. Alternatively, I launch a set number of AnyBar icons, so I can make sure they are open by counting the number of lines returned from the process list (the [ ] idea was from stackoverflow):

$ ps aux | grep -i '[a]nybar'
kyleking         9728   0.0  0.1  2579936  13844   ??  S    10:54AM   0:00.15 /opt/homebrew-cask/Caskroom/anybar/0.1.3/AnyBar.app/Contents/MacOS/AnyBar
kyleking         9726   0.0  0.1  2579936  14020   ??  S    10:54AM   0:00.16 /opt/homebrew-cask/Caskroom/anybar/0.1.3/AnyBar.app/Contents/MacOS/AnyBar
kyleking         9567   0.0  0.1  2579936  14220   ??  S    10:51AM   0:00.33 /opt/homebrew-cask/Caskroom/anybar/0.1.3/AnyBar.app/Contents/MacOS/AnyBar

Then to quit the app from a shell prompt, I'm just using:

sudo kill $(ps aux | grep -i '[a]nybar' | awk '{print $2}')

Is there a way to build something like this in Applescript or built-in to AnyBar?

@tonsky
Copy link
Owner

tonsky commented May 29, 2016

I think this is a problem that cannot be addressed by Anybar internally, because, well, it might be not running at all when you need to test it. Hence, this should be solved by external tools. ps approach seems ok to me. Do you have any particular issues with it?

@KyleKing
Copy link
Author

Thanks @tonsky. The ps method works much better than expected and I really only wondered if there was a better way

@Dima-369
Copy link
Contributor

Dima-369 commented Nov 2, 2020

I found that using lsof -Pn -i4 is really simple to parse because it lists the application along with its ports. It outputs:

COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
AnyBar    44361 Gira    3u  IPv4 0x6ac97d677e737941      0t0  UDP *:1738
AnyBar    44462 Gira    3u  IPv4 0x6ac97d677e7355e9      0t0  UDP *:1739

Maybe it's useful for someone :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants