5

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?

  • I’ve edited this a bit. You will want to ask a follow on question, showing your script progress if you get stuck with sudo or permissions. – bmike Dec 5 '19 at 10:31
6

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

  • 1
    You can also create a service. The instructions are given by clicking the link Making a Systemwide Service, which is at the bottom of the webpage you have linked to. In either case, you probably would want AppleScript ask for a password in a popup menu before running the script as root. – David Anderson Dec 5 '19 at 7:58
  • Hm. This kinda works — at least I can quickly access them. One minor problem is that just running some command keeps script running (which is good), but you can't stop that command by stopping the script (like described in this question) and I'll have to use second script just to send stop command. Or is there a way to run something on script stop? – Fullmoon Dec 6 '19 at 9:19
  • Update — turns out Script menu allows running bash scripts. And in this case stopping running script actually works. – Fullmoon Dec 6 '19 at 9:44
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .