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


Click here to return to the 'updated version' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]