BitBar - anyone else playing with it?

Is anyone else finding a reason to play with BitBar? I got interested after reading from @MacSparky and @drdrang about their use of this interesting little utility, that allows you to put the output of any script you write (or otherwise obtain) into the menu bar.

Of course, it’s a bit problematic when you have limit menu bar space, but I installed it to play with it and now I’m thinking about how I might want to use it.

So far, I have generated the following scripts, just playing around:

  1. Put my computer’s “external” IP address, eg the what is exposed to the internet, into the menu bar, with a drop down that shows any “internal” (eg LAN-assigned) IP addresses into the dropdown.
  2. Put the OmniFocus tasks that have various assigned tags into submenus of a menubar item called “OF” so I can quickly take a look at tasks with these tags. Each tag is a clickable link that jumps to that task in OmniFocus.

So far just playing around, and not sure if either of these scripts are long-term keepers or not. Wondering if anyone else is playing with BitBar?

In case anyone is curious, here are the two scripts:

#!/bin/zsh

# External IP address
EXTERNAL=$(curl -s ipecho.net | grep "Your IP is" | sed -n -e 's?^.*Your IP is \(.*\)</h1>$?\1?p')
if [[ $EXTERNAL != "" ]]
then
	echo $EXTERNAL
else
	echo "No Internet Cxn"
fi

echo "---"

# Internal IP addresses
while read LINE
do
	INTERFACE=$(echo $LINE | sed -n -e 's/^([0-9]) \(.*\)$/\1/p')
	if [[ $INTERFACE != "" ]]
	then
		while read LINE2
		do
			IP=$(echo $LINE2 | sed -n -e 's/^IP address: \(.*\)$/\1/p')
			if [[ $IP != "" ]]
			then
				echo "$INTERFACE: $IP | color=black"
			fi	
		done < <(networksetup -getinfo "$INTERFACE")
	fi
done < <(networksetup -listnetworkserviceorder)```


#!/usr/bin/osascript

set _output to "OF" & return & "---"
set _taglist to {"atdl", "pt-fu"}

tell application "OmniFocus"
	
	repeat with _tagname in _taglist
		
		tell the front document
			
			set _tag to (the first flattened tag whose name is _tagname)
			set _tasks to (every flattened task where its tags contains _tag)
			set _output to _output & return & _tagname
			repeat with _task in _tasks
				set _href to "omnifocus:///task/" & (id of _task)
				set _output to _output & return & "--" & (the name of _task) & " | color=green href=" & _href
			end repeat
			
		end tell
		
	end repeat
	
	return _output
	
end tell

I use BitBar to show me the status of my VPN connection because I often forget to turn it off.

I have an alias set up on zsh that connects to the VPN via openconnect and writes the status to a text file. the BitBar script just prints the contents of the text file.

I tried it once. Don’t have a need for any extra information in my menu bar. And if I needed this functionality I’d use Hammerspoon, which is already running anyway.

Less is more. Especially when it comes to background applications.

Something I’m doing with AnyBar that probably can be done with BitBar as well:

A Jenkins build traffic light that indicates whether my branch built correctly (green) or not (red).

I use it to check the state of my Parallels VMs and their IP addresses.

I use it to list Xcode project files and playground files, clicking one brings the project up in Xcode.

A little behind the scenes: we talked about BitBar in this week’s episode of Automators with a very special guest! The episode will be out on Friday.

5 Likes

Looking forward to that, @RosemaryOrchard.

Neal, Nice work! I’ve added this to my list of growing bitbar plugins to check out.

Here’s another idea: This one puts a list of recently modified / created files into the menu bar. I have no idea what (if anything) I am going to use this for. Maybe make the links clickable to go open a recently changed file, or open the enclosing folder in Finder.

(And yes, I know that you can show this data in the :apple: menu, but you cannot set up your own href’s there as you can if you modify this BitBar script.)

Note that you can add any other subfolders that you like to the list of Desktop and Documents (such as Downloads). I exclude all files starting with a ‘.’ character or in a folder starting with a ‘.’ as well. You may wish to do something different.

#!/bin/zsh

echo '🗂'
echo '---'

find /Users/<user>/{Documents,Desktop} -atime 0 -type f \! -iname '.*' -print

I don’t know if anyone else is following this thread, but in case you are…

Here is a rewrite of the script to handle recently modified/created files. I switched it to use mdfind which turns out to be much faster than find, by searching the Spotlight database instead of scanning every file on disk.

It also makes each file a clickable link which opens a Finder window to show the selected file.

The FOLDERS array variable sets the places that I want to search for new files, as I don’t want to show files created in hidden folders, or Pictures or Movies or whatever. You can tailor to your needs.

#!/bin/zsh

# If we have a commmand line argument, then that should be the path to the
# file to show in the finder. Otherwise, we are just populating the
# dropdown menu

if [[ $1 != "" ]]
then
	open -R "$1"
	/usr/bin/osascript -e "tell application \"Finder\" to activate"
	exit 0
fi

# --------------------------------------------------
# No command line argument, so need to create menu of recently changed files

echo '🗂'
echo '---'

FOLDERS=(
	"SynologyDrive"
	"ScannedDocuments"
	"Documents"
	"Desktop"
	"Downloads"
)

for FOLDER in $FOLDERS[@];
do
	mdfind -onlyin $HOME/${FOLDER} \
		'(((kMDItemFSCreationDate >= $time.now(-86400)) || (kMDItemContentModificationDate >= $time.now(-86400)) || (kMKItemUserModifiedDate >= $time.now(-86400))) && (kMDItemContentType != "public.folder"))' |
		while read LINE
		do
			echo "${LINE} | color=black bash=$0 param1=${LINE} terminal=false"
		done
done
1 Like