Documentation

Scripts Directory

CmdBar looks at $HOME/.cmdbar directory for scripts to execute. Scripts have to follow these naming conventions: name.time.extension OR name.time. For example, transmission.2s.sh is a shell script named transmission that will execute every two seconds OR main.2m is an executable named main that will execute every two mintues. You can use “s” for seconds, “m” for minutes, “h” for hours, and “d” for days. Although you can set days for execution interval, it is pointless. CmdBar reloads scripts whenever MacOS wakes up -- this might change in the future. Current implementation could be useful if your computer never goes into sleep mode.

If you wish to store your scripts directory in other place, you can create a symbolic link, but otherwise $HOME/.cmdbar is the only location CmdBar looks in.

// example
ln -s /Users/home/.config/.cmdbar /Users/$USER/.cmdbar

Reload Scripts

You can click the blue button to reload the current script. Hold shift and click the blue button to reload all scripts. This might be useful whenever you add or remove scripts from .cmdbar.

Launch At Login

You can click the orange button to toggle launch at login.

Writing Scripts

There are no restrictions on the type of executable you can use, for as long as they write to standard output.

Note

Script or executable must have execution premission.

chmod +x script.2s.sh 

The first line of the output will be used to display as a title of a status bar button, and the rest will go into the body of the popover.

#!/bin/sh

echo "👋"              # button title
echo "Hello, world!"   # body
echo "Hello, seaman!"

Will output:

👋
Hello, world!
Hello, seaman!

Warning

Most likely you will launch CmdBar through Finder, as a result CmdBar will not borrow the environment properties your Terminal has set. For this reason, your shell scripts must use absolute paths to programs (e.g. not brew outdated, but /opt/homebrew/bin/brew outdated). Esentially, everything that is not in /usr/bin, /bin, /usr/sbin, /sbin should have an absolute path. To find out absolute path of a program, you can use which command (e.g. which brew).

Example Scripts

Streaks

#!/bin/sh

set -e

symbol="🔄"
yay="✅"
nay="☑️"
started="2023-10-15"

today() { date "+%Y-%m-%d"; }

difference() {
    date1=$1
    date2=$2

    start=$(date -j -f "%Y-%m-%d" "$date1" "+%s")
    end=$(date -j -f "%Y-%m-%d" "$date2" "+%s")
    difference=$(( (end - start) / (60 * 60 * 24) ))

    echo $difference
}

is_streak() {
    days=$1
    
    date=$(date -v+"$days"d -j -f "%Y-%m-%d" "$started" "+%Y-%m-%d")
    diff=$(difference "$(today)" "$date")

    if [ "$diff" -lt 1 ]; then
        echo $yay;
    else
        echo $nay;
    fi
}

echo "$symbol$(difference "$started" "$(today)")"

echo "Started on $(date -jf "%Y-%m-%d" "$started" "+%a, %b %e")."
echo "⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"
echo "$(is_streak  7)  7 days ($(date -v+7d  -j -f "%Y-%m-%d" "$started" "+%a, %b %d"))"
echo "$(is_streak 14) 14 days ($(date -v+14d -j -f "%Y-%m-%d" "$started" "+%a, %b %d"))"
echo "$(is_streak 30) 30 days ($(date -v+30d -j -f "%Y-%m-%d" "$started" "+%a, %b %d"))"
echo "$(is_streak 60) 60 days ($(date -v+60d -j -f "%Y-%m-%d" "$started" "+%a, %b %d"))"
echo "$(is_streak 90) 90 days ($(date -v+90d -j -f "%Y-%m-%d" "$started" "+%a, %b %d"))"
echo "⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯"