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


Click here to return to the 'Controlling iTunes from the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Controlling iTunes from the Terminal
Authored by: reasonstoprefer on Jul 06, '09 10:51:50AM
I am using this script to control my itunes with my BlackBerry 8820. So far it has been a great success. All it takes is midpSSH which is SSH software for mobile phones. If you have a dynamic IP address it would be useful to use a service that will keep it updated and linked to a URL.

http://img197.imageshack.us/img197/6887/photo1afm.jpg
http://img196.imageshack.us/img196/2147/picture3qlf.jpg

I edited this script in an attempt to make it more useful. Since this was (almost) my first attempt to do something with applescript, I only made limited additions to the code. On the other hand, it hints at how much potential the script has. Here is what I added:
## search and play
"search" ) 
clear;
osascript -e "set searchTerm to\"$2\"" -e 'tell application "iTunes"
if playlist searchTerm exists then
		set max to number of tracks of playlist searchTerm
		set output to {}
		set counter to 0
		repeat while counter < max
			set counter to counter + 1
			set output to output & "[" & counter &".] " & name of track counter of playlist searchTerm & "
"
		end repeat
		reveal playlist searchTerm
		play playlist searchTerm
		set thisPlaylist to current playlist
		set thisArtist to artist of current track
		set thisTrack to name of current track
		set trackNumber to index of current track
		set output to "Currently playing track << " & trackNumber & ". " & thisTrack & " \\\\ " & thisArtist & " >> 

" & output
		get output
		
	else
		make playlist with properties {name:searchTerm}
		duplicate (tracks of library playlist 1 whose artist contains searchTerm or album contains searchTerm or name contains searchTerm) to playlist searchTerm
		set max to number of tracks of playlist searchTerm
		set output to {}
		set counter to 0
		repeat while counter < max
			set counter to counter + 1
			set output to output & "[" & counter &".] " & name of track counter of playlist searchTerm & "
"
		end repeat
		reveal playlist searchTerm
		play playlist searchTerm
		set thisPlaylist to current playlist
		set thisArtist to artist of current track
		set thisTrack to name of current track
		set trackNumber to index of current track
		set output to "Currently playing track << " & trackNumber & ". " & thisTrack & " \\\\ " & thisArtist & " >> 

" & output
		get output
	end if
	
	
end tell'; 
break ;; 

##skip to track in playlist
"skipto" ) 
clear;
osascript -e "set skipTo to $2" -e 'tell application "iTunes"
	play track (skipTo) of current playlist
	set max to number of tracks of current playlist
	set output to {}
	set counter to 0
	repeat while counter < max
		set counter to counter + 1
		set output to output & "[" & counter & ".] " & name of track counter of current playlist & "
"
	end repeat
	set thisPlaylist to current playlist
	set thisArtist to artist of current track
	set thisTrack to name of current track
	set trackNumber to index of current track
	set output to "Currently playing track << " & trackNumber & ". " & thisTrack & " \\\\ " & thisArtist & " >> 

" & output
	get output
end tell';
break;;
It adds a basic search function. You can search for a song, album, or artist with the command itunes search searchterm with itunes being the name of the script and searchterm being the search term. This will call up a list of search results and start playing them from the top. To skip to a number on that list you enter itunes skipto 10 (replace 10 with the number of the track you want to play).

[ Reply to This | # ]