Darkland | net

MPD/NCMPCPP Launch Script

Published on 24 July, 2016 by Amanda

***NOTE: This page is wildly obsolete.***
Heavily commented for copy-pasting from this page.

The impetus for this script was getting frustrated with not remembering whether mpd was running when I launched ncmpcpp, then having to close ncmpcpp and launch mpd, then relaunching ncmpcpp.

Why not just add mpd to $HOME/.config/autostart? Because, this helps the desktop load faster on the crumby laptops that I'm currently using, and I also launch ncmpcpp from a custom desktop launcher, and I just don't have to think about it. And the fun of it, of course. Mostly the fun of it.
#!/bin/bash
# The purpose of this script is to run ncmpcp, and if
# necessary launch mpd. ncmpcpp will complain and not
# function if it can not connect to mpd, which runs as a
# daemon, and plays the music. It requires a frontend
# client to attach to it to and control its function.
# Rename the script to whatever name fits your
# environment before using. Remember to change
# permissions before attempting to run the script.
# "chmod 755 $HOME/bin/[script name]"

# Tests to see if mpd is running and if so sends output
# from "ps aux" to /dev/null before continuing.
if ps aux | grep '[/]usr/local/bin/mpd' 1> /dev/null
    then

# This section prints to screen that the script is
# launching ncmpcpp so I know if mpd was running or
# not and pauses half a second before actually
# launching ncmpcpp.
    printf "Launching ncmpcpp."
        sleep 0.5s
        /usr/local/bin/ncmpcpp
    else

# If the mpd daemon is not running this section prints
# to screen that the script is loading the mpd daemon
# in to memory and then launching ncmpcpp. The script
# pauses for half a second before deleting the mpd.log
# file, and recreates a new empty log file. The script
# then loads the mpd daemon in to memory, and launches
# ncmpcpp. The reason this script deletes $HOME/.mpd/mpd.log
# is to prevent it from growing too large, as neither
# mpd or ncmpcpp limit the file's growth.

    printf "Loading mpd daemon. Launching ncmpcpp."
     sleep 0.5s
        rm $HOME/.mpd/mpd.log 1> /dev/null
        touch $HOME/.mpd/mpd.log 1> /dev/null
    /usr/local/bin/mpd && /usr/local/bin/ncmpcpp
fi
Back