Logitech Media Server Status Display

Show whether Logitech media Server is running or not. Quickly start/stop it, access its UI etc.

Image preview of Logitech Media Server Status Display plugin.

check-lms.10s.pl

Edit
Open on GitHub
#!/usr/bin/perl -w

# <xbar.title>Logitech Media Server Status Display</xbar.title>
# <xbar.version>v1.2.0</xbar.version>
# <xbar.author>Michael Herger</xbar.author>
# <xbar.author.github>michaelherger</xbar.author.github>
# <xbar.desc>Show whether Logitech media Server is running or not. Quickly start/stop it, access its UI etc.</xbar.desc>
# <xbar.image>http://www.herger.net/slim/BitBar/lms-bitbar.png</xbar.image>
# <xbar.dependencies>Logitech Media Server</xbar.dependencies>

use strict;

BEGIN {
	if (!$ENV{BitBar}) {
		require Data::Dump;
	}
}

use constant STRINGS => sub {
	my $lang = uc(substr(`/usr/bin/defaults read -g AppleLocale` || 'EN', 0, 2));

	my $localizations = {
		NOT_FOUND => {
			DE => 'Logitech Media Server wurde nicht gefunden.',
			EN => 'Logitech Media Server can\'t be found'
		},
		LMS_RUNNING => {
			DE => 'Logitech Media Server wird ausgefĂĽhrt',
			EN => 'Logitech Media Server is running'
		},
		LMS_NOT_RUNNING => {
			DE => 'Logitech Media Server läuft nicht',
			EN => 'Logitech Media Server is not running'
		},
		LMS_IS_STARTING => {
			DE => 'Logitech Media Server startet…',
			EN => 'Logitech Media Server is starting…'
		},
		START_LMS => {
			DE => 'Logitech Media Server starten',
			EN => 'Start Logitech Media Server'
		},
		STOP_LMS => {
			DE => 'Logitech Media Server anhalten',
			EN => 'Stop Logitech Media Server'
		},
		OPEN_WEB_CONTROL => {
			DE => 'Web-Steuerung öffnen…',
			EN => 'Open Web Control…'
		},
		OPEN_SETTINGS => {
			DE => 'Einstellungen öffnen…',
			EN => 'Open Settings…'
		},
		OPEN_PREF_PANE => {
			DE => 'Systemeinstellungen öffnen…',
			EN => 'Open Preference Pane…'
		},
		UPDATE_AVAILABLE => {
			DE => 'Software aktualisieren…',
			EN => 'Install software update…'
		}
	};

	return { map {
		$_ => ($localizations->{$_}->{$lang} || $localizations->{$_}->{EN})
	} keys %$localizations };
}->();

use constant PREFPANE_LINK => STRINGS->{'OPEN_PREF_PANE'} . '|bash=/usr/bin/open param1=/Library/PreferencePanes/Squeezebox.prefPane terminal=false';

use constant LMS_ON => 'iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAgtpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAgICA8dGlmZjpDb21wcmVzc2lvbj4xPC90aWZmOkNvbXByZXNzaW9uPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICAgICA8dGlmZjpQaG90b21ldHJpY0ludGVycHJldGF0aW9uPjI8L3RpZmY6UGhvdG9tZXRyaWNJbnRlcnByZXRhdGlvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cg9FKpMAAAtISURBVFgJhZhbjF1VGce/vfe5zJzLzHQ6M+3MWAoqTCnQIliohIhJTQRMvIRQUx+MGBMNNr4aX3z3wTdMJOHJGEtIfIAESjSISIylAwNloFewAp1LO9NOp+e+z774+699zmEMD+yZtc/ee631ff/1/y7r4hn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27fNaU4wzgpduPScAu379enUrLn3m1ZoS+AYQb7LS16xZU33//felOaUJ21XeEDJFds+OHTuKYZ6TVbjOHv+By3MGYuN476pu375dgJgDJo8O/KnbJd96nRYvXlwUxttriYJdIfcplB5PmjSpADh37lyJgKNBlPGJSPKnYulDdhcwmqc/cuTQC4uDsTMUNMdh5YiuKUTKXVtFyDnBgLuSPokS9WEeUWiOUuM0YA04aRFBUQHG8aFH8RToCt21kOlsiXBfDjDfBRVAdpOzBFHigJMSY8Z5mlFNw4W54cc80gPJKdtedOwwO9qz0cMXxVnXFRhqYedSSxj6NYS+W7p0aWestZw9e7aKDwHFA54BYzeIlueZqACtLjJiCZByMhogKZtgREeabHU64osLkWrJkiWdwVuwtEQN7AxjP0YxtsVB1hEfHnr3tK3VjJ3Fq7zqApVgRCMdaAQDBAAeHT1R7OCO2CSt8dh6F8HYWSr61KlT6+Jrx89udxHK9v379zfHXC3y3BTImxhinFfAeDjqM1rSKFoZMREVFTWjSZVe2sOB7nhV6l6wYEHXihUrOsNuK9BRJuviGPkFoPLlyjeiKOafYnuX+6k8U5B10ug9T0VGSyDZA54pE6msp5SxzoF8QYwPVu8igpvnzp37Cyy55wson/TiYPx7pOVvEYXpEZGQ/6KAEQB5n02NaJkixvFn5EQ0x0BkC3mf9C4FkF+jTHauX7/+HjDROv8Nn3rXVXWcuWAAAAAASUVORK5CYII=';

my $status = LMS_OFF;

my $INSTALLATION_FOLDER = '/Library/PreferencePanes/Squeezebox.prefPane/Contents/Resources';

my $items;

if ( !-d $INSTALLATION_FOLDER ) {
	$items = STRINGS->{'NOT_FOUND'} . '|color=#ff0000';
}
else {
	my $port = `$INSTALLATION_FOLDER/check-web.pl`;
	$port *= 1;
	
	if ( $port ) {
		$items = sprintf(
 			"%s\n%s| href=http://localhost:$port\n%s| href=http://localhost:$port/settings/index.html\n---\n%s|bash=$INSTALLATION_FOLDER/stop-server.sh terminal=false refresh=true", 
			STRINGS->{LMS_RUNNING},
			STRINGS->{OPEN_WEB_CONTROL},
			STRINGS->{OPEN_SETTINGS},
			STRINGS->{STOP_LMS}
		);
			
		$status = LMS_ON;
	}
	else {
		my $server = `$INSTALLATION_FOLDER/get-server.sh`;
 		$server =~ s/\s*//sig;

		if ( $server ) {
			$items = STRINGS->{LMS_IS_STARTING};
		}
		else {
			$items = sprintf(
				"%s\n%s|bash=$INSTALLATION_FOLDER/start-server.sh terminal=false refresh=true", 
				STRINGS->{LMS_NOT_RUNNING}, 
				STRINGS->{START_LMS}
			);
		}
	}
		
	$items .= "\n---\n" . PREFPANE_LINK;

	my $versionFile = $ENV{"HOME"} . '/Library/Caches/Squeezebox/updates/server.version';
	my $installer = '';

	open(UPDATEFLAG, $versionFile) && do {
		local $_;
		while ( <UPDATEFLAG> ) {

			chomp;

			if (/(?:LogitechMediaServer|Squeezebox|SqueezeCenter).*/i) {
				$installer = $_;
				last;
			}
		}
		
		close UPDATEFLAG;
	};	
	
	if ($installer) {
		$items .= "\n" . STRINGS->{UPDATE_AVAILABLE} . "|color=green terminal=false bash=/usr/bin/open param1=$installer";
		print '⇧';
	}
}

print qq(|image=$status
---
$items
);


1;