Show the output of a shell command in your menu bar
This guide first appeared on multimeterapp.com. Multimeter is a Mac menu bar app that turns any number into a live meter. A Script meter runs a command with zsh every 30 seconds (or as often as every 2) and shows the number it prints. If you can get a number out of Terminal, you can put it in the menu bar. Add the meter Choose Add Meter… and pick Script. Paste the command and choose how often it runs. If it prints JSON, add a key path. Set a range if the number isn’t a percentage. Scripts need the direct download version of Multimeter from this site, which is the one on sale now. The Mac App Store sandbox doesn’t let apps run your scripts; there, have the script send a link or write a file. How commands run With /bin/zsh -c, as you. /opt/homebrew/bin, /usr/local/bin, ~/.local/bin and ~/.bun/bin are added to the PATH. Your ~/.zshrc is not loaded (it only runs for interactive shells), so aliases and functions defined there aren’t available. Use full commands, or put shared settings in ~/.zshenv. A command that runs longer than 10 seconds is stopped. A new run never starts while the last one is still going. Only standard output is read; errors on standard error are ignored. Choose Refresh Now from the meter’s menu to run it immediately. What the command should print Web addresses, files and scripts all read the same two formats. A plain number, or any text with a number in it. Multimeter takes the first number it finds, and drops thousands separators between digits, so 1,284 stars reads as 1284. JSON. Either a bare number, or an object with value and any of these extras: meter.json { "value": 38, "min": 0, "max": 50, "label": "DEPLOY", "unit": "today", "formatted": "38 of 50" } Pointing at bigger JSON you don’t control, like an API response? Give the meter a key path. Dots walk into objects and numbers pick array items: data.items.0.count. Numbers inside strings work too ("67012.45"), and true/false count as 1 and 0. Without min and max the range is 0 to 100, so for bigger numbers set a range in Customize This Meter… or send max. Commands to start from Files in Downloads ls ~/Downloads | wc -l Uncommitted changes in a repo git -C ~/code/my-app status --porcelain | wc -l Running Docker containers docker ps -q | wc -l One-minute load average sysctl -n vm.loadavg | awk '{print $2}' Open pull requests waiting for your review (GitHub CLI) gh search prs --review-requested=@me --state=open --json number -q length A number from an API that needs a token curl -s -H "Authorization: Bearer $(cat ~/.config/mytoken)" https://api.example.com/stats | jq .active_users Commands that can be slow (network calls, big directories) should run every minute or less often. Check timing in Terminal with time first. Commands that take longer than 10 seconds, like brew outdated (which can take 20 seconds or more), belong in a launchd job that writes a file for a File meter; the speed test recipe shows how. Ready-made, tested commands for dozens of services are in the recipes. Check it worked Run the command in Terminal first: it should print one number. Paste it into the meter and choose Refresh Now; the meter should show the same number. Troubleshooting What the meter says, why, and what to do Symptom Cause Fix The script didn’t print a number The output has no digits, or the number is on standard error. Run it in Terminal and check. Add 2>&1 if the tool prints to standard error. The script took longer than 10 seconds A slow network call or a command waiting for input. Add timeouts (curl -m 5, ssh -o ConnectTimeout=5 -o BatchMode=yes) and make sure nothing asks for a password. Works in Terminal, “command not found” in the meter The tool lives outside the folders on the meter’s PATH, or is an alias from ~/.zshrc. Use the full path (find it with which tool). Scripts need the version from multimeterapp.com This copy of Multimeter came from the Mac App Store. Use a link or a file instead, or the direct download version. Next Keep your server’s load in the menu bar Read a web address directly, without a script The Needle Gauge face Ready-made recipes by topic All guides
This is a summary aggregated from Dev.to. Read the complete article on the original site:
Read full article at Dev.to