Emacs Switcher

My favorite WM is certainly Herbstluftwm - partially because I’ve grown accustomed to it, but also because I find it very easy to script for. herbstclient is, despite the weak community support you find from small projects like this, fairly easy to script for. Here’s a favorite of mine that jumps to Emacs no matter what workspace you’re on.

jump() {
    flag=0
    for i in $(herbstclient foreach C clients. echo C)
    do
        if [ $(herbstclient attr $i.class) = "Emacs" ]; then
            prefix="clients."
            herbstclient jumpto ${i#$prefix}
            notify-send "Jumping to $(herbstclient attr $i.title)"
            flag=1
            break
        fi
    done
    if [ $flag -eq 0 ]; then
        emacsclient -c -a emacs
    fi
}

if [[ -e "/tmp/emacs1000/server" ]]; then
    case $1 in
        "")
            jump
            ;;
        "Todo")
            emacsclient -e "(org-todo-list)" -c -n
            notify-send "Spawning TODO list"
            ;;
        "Agenda")
            emacsclient -e "(org-agenda)" -c -n
            notify-send "Spawning AGENDA list"
            ;;
        *)
            emacsclient $1 -r -n
            jump
        ;;
    esac
 else
    notify-send "No Emacs daemon exists; Creating one!"
    emacs --daemon-bg
    emacsclient -c -a emacs
fi

Also it will create an Emacs daemon with an associated window if none are available.