A way to run console commands in menu bar?

I have a couple of console commands that I a) want to run and stop at demand (optionally automated) and b) without opening terminal window and/or leaving it open, ideally from menu bar. Some of them require root.

(One example of such command is proximac — it forces certain apps to use proxy, useful when they don’t respect system proxy settings. I want to run it when I connect to SOCKS proxy at work, and stop when I leave)

What’s the best way or app to launch command line tools from the menu bar?


Solution 1:

You can enable the Script menu from the built-in Script Editor.app: Preferences → General → Show Script menu in menu bar.

Then you can place any AppleScript in this menu by putting the script in your Scripts folder.

To add user-level scripts to the script menu, save them into the ~/Library/Scripts/ folder of your user directory. For quick access to this folder, select Open Scripts Folder > Open User Scripts Folder from the script menu. When you do this, the folder is automatically created if it doesn’t already exist.

https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/UsetheSystem-WideScriptMenu.html

Solution 2:

BitBar (GitHub) is a useful tool for running scripts from the menubar, and it has a lot of built-in functionality like being able to show script output, create dropdown items, perform actions on click, and more. See the Plugin API section of the GitHub README for a description of all the functionality you can use.

Here's an example from the site showing asset prices on some exchange:

enter image description here