Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use a remote control with number buttons and iTunes Apps
I've set up a G4 Cube as an iTunes server (VCR, movie player, backup server, etc.) connected to an LCD TV, and I use an ATI Remote Wonder to control iTunes. The problem is that i find it quite uncomfortable to select a playlist with the Remote Wonder's cursor. You have to scroll the list down (move the cursor to the scroll bar), then select a playlist (move the cursor to the playlist).

So I thought I would write a script to ease the task of selecting a playlist. This script can easily be extended to allow the selection of a movie (or any other file).

#!/bin/sh

# get the playlists:
echo `/usr/bin/osascript << END | tr "," "\n" > playlists.tmp
try
	tell application "iTunes"
		set the_playlists to the name of every playlist
	end tell
end try
END
`
# get single characters (without the need to press enter) from std-in:
getc (){
   stty raw
   eval $1=`dd bs=1 count=1 2>/dev/null`
   stty cooked
}

cat playlists.tmp
# convert numbers to characters
while [[ $EXIT != "true" ]]; do
	getc CHARACTER
	clear
	case $CHARACTER in
		1)
			CHARACTER="[.]"
			;;
		2)
			CHARACTER="[2ABCabc]"
			;;
		3)
			CHARACTER="[3DEFdef]"
			;;
		4)
			CHARACTER="[4GHIghi]"
			;;
		5)
			CHARACTER="[5JKLjkl]"
			;;
		6)
			CHARACTER="[6MNOmno]"
			;;
		7)
			CHARACTER="[7PQRSpqrs]"
			;;
		8)
			CHARACTER="[8TUVtuv]"
			;;
		9)
			CHARACTER="[9WXYZwxyz]"
			;;
		0)
			CHARACTER="[0 _-]"
			;;
		q)
			exit
			;;
	esac
	
	SEARCH=${SEARCH}${CHARACTER}
	
	if [[ `grep -i "$SEARCH" playlists.tmp | wc -l` == "       1" ]]; then
		PLAYLIST=`grep -i "$SEARCH" playlists.tmp | perl -pe 's/^+[\t ]//g'`
		EXIT="true"
	elif [[ `grep -i "$SEARCH" playlists.tmp | wc -l` == "       0" ]]; then
		SEARCH=""
	fi
	grep -i "$SEARCH" playlists.tmp | tr '[A-Z]' '[a-z]' | sed s/"\($SEARCH\)"/"[\1]"/

done

echo "--------"
echo $PLAYLIST
echo "--------"

/usr/bin/osascript << END
	tell application "iTunes"
		set the_playlist to item 1 of (every playlist whose name is "$PLAYLIST")
		play track 1 of the_playlist
	end tell
	tell application "iTunes" to activate
END

sh $0


The script does the following:
  1. Queries iTunes for the name of all playlists (I first tried parsing the XML file, but had problems with special characters) and saves the list to a file (when storing it in a variable I lost the line breaks)
  2. Defines the function getc to switch Terminal to raw-input-mode and allow the input of single characters without the need of having to press Return after each character
  3. Runs a loop to get the input characters.
  4. Turn- the numbers of the input characters to RegEx snippets to match the characters printed on the number keys of my remote. Exits, if the input character is a q.
  5. Appends the input character to the search string.
  6. Checks for unique matches.
    1. If yes, it exits the loop.
    2. If no, runs grep with the search string in the playlists so show how good the match is so far.
    3. If there is no match, starts over with an empty search string.
  7. After the loop, the match is displayed and iTunes is told to play the chosen playlist.
  8. Brings iTunes to the front.
  9. Restarts the script.
On my Cube the Terminal isn't used for anything else (I ssh into the machine if I need access) so I can dedicate the remote's keys to Terminal and this script, and run Terminal with a huge font. In iTunes I have a key that brings Terminal (with the infinite running script) to the front.

This script can easily be extended to work with other keys for other actions. It seems to be uncomfortable but works surprisingly well! Have fun!

    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[5,812 views]  

Use a remote control with number buttons and iTunes | 8 comments | Create New Account
Click here to return to the 'Use a remote control with number buttons and iTunes' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use a remote control with number buttons and iTunes
Authored by: waffffffle on May 04, '06 07:52:53AM

The number pad on my ATI Remote Wonder has no letters, only numbers 0-9. Do you have version II?



[ Reply to This | # ]
no.
Authored by: nick on May 04, '06 02:03:37PM

its version one. i saw pictures of v1 without characters online, but mine has characters printed above the number-keys.



[ Reply to This | # ]
updated version
Authored by: nick on May 04, '06 02:11:22PM
the regex for the wildcard now includes exactly one word instead of any number of any character. works better for me.

#!/bin/sh

# get the playlists:

echo `/usr/bin/osascript << END | tr "," "\n" | perl -pe 's/^+[\t ]//g' > .playlists.tmp
	tell application "iTunes"
		set the_playlists to the name of every playlist
	end tell
	return the_playlists
END
`

# obviously i'm not a RegEx/sed/awk/perl wizzard!

# get single characters (without the need to press enter) from std-in:
getc (){
	stty raw
	eval $1=`dd bs=1 count=1 2>/dev/null`
	stty cooked
}

cat .playlists.tmp

SEARCH="^"

# convert numbers to characters
while [[ $EXIT != "true" ]]; do
	getc CHARACTER
	clear
	case $CHARACTER in
		1)
			# any character
			CHARACTER="[^[:blank:]]*[[:blank:]+]"
			;;
		2)
			CHARACTER="[2ABCabcÄä]"
			;;
		3)
			CHARACTER="[3DEFdef]"
			;;
		4)
			CHARACTER="[4GHIghi]"
			;;
		5)
			CHARACTER="[5JKLjkl]"
			;;
		6)
			CHARACTER="[6MNOmnoÖö]"
			;;
		7)
			CHARACTER="[7PQRSpqrsß]"
			;;
		8)
			CHARACTER="[8TUVtuvÜü]"
			;;
		9)
			CHARACTER="[9WXYZwxyz]"
			;;
		0)
			CHARACTER="[0 _-]"
			;;
		Q)
			# quit
			exit
			;;
		R)
			# repeat search
			SEARCH="^"
			CHARACTER=""
			;;
		S)
			# select top playlist
			SELECT="true"
			CHARACTER=""
			;;
		E)
			# end of line
			CHARACTER="$"
			;;
	esac

	if [[ $SELECT = "true" ]]; then
		PLAYLIST=`grep -i "$SEARCH" .playlists.tmp | head -1`
		EXIT="true"
	fi

		SEARCH=${SEARCH}${CHARACTER}

	if [[ `grep -i "$SEARCH" .playlists.tmp | wc -l` == "       1" ]]; then
		PLAYLIST=`grep -i "$SEARCH" .playlists.tmp`
		EXIT="true"
	elif [[ `grep -i "$SEARCH" .playlists.tmp | wc -l` == "       0" ]]; then
		SEARCH="^"
	fi

	grep -i "$SEARCH" .playlists.tmp | tr '[A-Z]' '[a-z]' | sed s/"\($SEARCH\)"/"[\1]"/ | head -20
	echo "[$SEARCH]"
	echo ""
	echo "0=_   1=*   OK=line-end   MENU=repeat-search   PLAY=play-top-playlist"
	echo "---------------------------------------------------------------------"

done

echo "--------"
echo $PLAYLIST
echo "--------"

PLAYLIST=`echo "$PLAYLIST" | iconv -f "UTF-8" -t "macroman"`

/usr/bin/osascript << END
	tell application "iTunes"
		set the_playlist to item 1 of (every playlist whose name is "$PLAYLIST")
		play track 1 of the_playlist
	end tell
	tell application "System Events"
		tell application "iTunes" to activate
		key code 37 using command down
	end tell
END

sh $0


[ Reply to This | # ]
and the command-letters are capitals now.
Authored by: nick on May 04, '06 02:17:17PM

forgot to mention that.



[ Reply to This | # ]
Use a remote control with number buttons and iTunes
Authored by: lozanobarcia on May 05, '06 02:20:34AM

Why not using the free app MediaCentral from Equinux Instead?
It works perfectly with ATI RW all versions and the interface is almost the same than FrontRow

---
...___Albert



[ Reply to This | # ]
because it needs tiger.
Authored by: nick on May 05, '06 02:46:13AM

i have panther installed on my media-cube and all MediaCentral-like solutions i found needed tiger.



[ Reply to This | # ]
RE: because it needs tiger.
Authored by: lozanobarcia on May 06, '06 08:41:55AM

Ah... pls excuse me for my mistake. I'm also using a Cube (450 MHz) for the same purpose as you but with Tiger instead Panther. That's why I was thinking on MediaCentral for your system.
My apologies.

---
...___Albert



[ Reply to This | # ]
no problem...
Authored by: nick on May 08, '06 02:22:54AM

...i'm glad if anyone can point me to a media-center software that doesn't need tiger.



[ Reply to This | # ]