Searching iTunes from NSTextField?

Hey all,

My first thread here.

I am just wondering, whether you can help me with some code I did have in another project. This project failed when I added a few new features that made it un compilable. I then trashed it and tried to start again, but in my new one (with the implemented features), I am missing the iTunes Search Code that I had.

The code I had did the following,

A Button would bring up the Dialog (programmatically gen) and then I would enter a Track name. If there were dupes, it would display a list view with the option of whatever one to play and if there were no dupes, iTunes would simply “Play” the track.

I have a rudimentary form now, it searches iTunes according to whatever is in my “Title Search Box” in my App, But I need to be able to search the Artist. This is what the last code had.

I am sure Jobu or one of the other very good gurus on this forum could help me as I am at my Wits end trying to implement it myself.

Cheers,

B

iTunes Search Code That I Already Have

set songText to contents of text field “Search” of window “BEZEL”

tell application “iTunes”
play track songText of playlist "Music
end tell

PLEASE HELP!!! :D:D:D:D:D:D:D:D

Model: Intel C2D
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)

Hello,

Try this,


set theText to text returned of (display dialog "Enter Search Parameter:" default answer "")
	set foundItemList to {}
tell application "iTunes"
	set theList to search playlist "Music" for theText
	repeat with aItem in theList
		set theName to name of aItem
		set end of foundItemList to theName
	end repeat
	try
		set choosenItem to (choose from list foundItemList) as string
		play track choosenItem of playlist "Music"
	on error
		display dialog "No items found"
	end try
end tell



This is what I use

set songTitle to text returned of (display dialog "Enter the name of the song you want to play." default answer "")
set playTrack to ""
tell application "iTunes"
	set fixedIndexing to fixed indexing
	set fixed indexing to true
	
	repeat while playTrack is ""
		tell (tracks of (first playlist whose special kind is Music) whose name contains songTitle) to if (count) > 1 then --if you want to search for the artist replace "whose name" with "whose artist"
			set playTrack to my chooseTracks(name, artist, album, it)
		else if it is not {} then
			set playTrack to item 1 of it
		else
			try
				tell me to set songTitle to text returned of (display dialog "Your search turned up 0 results. Try again?." default answer "" buttons {"Cancel", "Go"} default button 2)
			on error -- user canceled
				set playTrack to false
			end try
		end if
	end repeat
	
	if playTrack is not false then
		tell application "iTunes"
			if (get version) as string < "7.1" then
				set Master_Playlist to library playlist 1
			else
				set Master_Playlist to first playlist whose special kind is Music
			end if
			set view of browser window 1 to Master_Playlist
		end tell
		
		play playTrack
	end if
	set fixed indexing to fixedIndexing
end tell
tell application "Finder" to set the visible of every process whose name is "iTunes" to false

on chooseTracks(trackNames, trackArtists, trackAlbums, tracksFound)
	set {tracksList, foundCount} to {{}, count tracksFound}
	repeat with i from 1 to foundCount
		if trackArtists's item i is "" then set trackArtists's item i to "Unknown"
		if trackAlbums's item i is "" then set trackAlbums's item i to "Unknown"
		set end of tracksList to trackNames's item i & " - " & trackArtists's item i & " (" & trackAlbums's item i & ")"
	end repeat
	
	set trackChosen to choose from list tracksList with prompt "Your search turned up " & foundCount & " results. Please specify which track you want to play."
	if trackChosen is false then return false
	
	set my text item delimiters to return
	set tracksList to tracksList as Unicode text
	set my text item delimiters to beginning of trackChosen
	set trackNumber to count of paragraphs of first text item of tracksList
	set my text item delimiters to ""
	return item trackNumber of tracksFound
end chooseTracks


Thhhhhhhhhhhhhhhhhhhhhhhhaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnk Yoooooooooooooooooooooooooooooooooooooouuuuuuuuuuuuuuuuuuuuu HENDO!!! This would have taken me ages. :D:D:D:D

I like this place now :smiley:

B