How To Smart Home: A Step by Step Guide to Your Personal Internet of Things

How To Smart Home: A Step by Step Guide to Your Personal Internet of Things

Author:Othmar Kyas
Language: eng
Format: mobi
Tags: Computers & Technology
Publisher: Key Concept Press
Published: 2015-03-28T22:00:00+00:00


Later, we will add the above scripts as commands to OpenRemote Designer, using the shell execution protocol. Since we will also display the track iTunes is currently playing, we need one more AppleScript based shell script, which determines if iTunes is playing, and, if this is the case, writes the result to the variable state:

state=`osascript -e 'tell application "iTunes" to player state as string'`;

If the variable state is set to playing we write current artist and track to the variables artist and track:

artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;

track=`osascript -e 'tell application "iTunes" to name of current track as string'`;

We design the script with the log file for the result to be provided as an argument. So if iTunes is playing, track and artist are written to the file specified as shell argument. Since we plan to use an html file as log, which shall be displayed by the OpenRemote web server, the files location shall again be in the web server root directory:

/ORC/webapps/controller

With that our script iTunesPlaying.sh reads to:

#!/bin/sh

#Retrieves currently played title from iTunes and writes to logfile - last entry will be overwritten

if [[ $# -lt 1 || $# -gt 1 ]];then

echo "$0: Argument error: playing.sh [log file]"

exit 2

fi

state=`osascript -e 'tell application "iTunes" to player state as string'`;

echo "iTunes is currently $state.";

if [ $state = "playing" ]; then

artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;

track=`osascript -e 'tell application "iTunes" to name of current track as string'`;

echo "Current track $artist: $track" > /Users/smarthome/shProject/ORC/webapps/controller/$1;

else

echo "iTunes is currently $state." > /Users/smarthome/shProject/ORC/webapps/controller/$1;

fi

To test we start an iTunes playlist and type

iTunesPlaying.sh playing.html

in the terminal window. If we now open the URL

http://localhost:8080/controller/playing.html

in a web browser, we should see a display of the playlist. We now can configure all scripts as commands in OpenRemote Designer. (Section 8.3)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.