ok, so i have code that when you click a button it prompts you to type a song name. If there is more than one result a list comes up. If ther is no results the dialog comes up telling you there was zero results. I want to change the first prompt so instead of a prompt it’s the contents of a text field (so when the user hits the search button it searches for and plays whatever they type. here is my old code. I still want a dialog to come up saying there is no results. Here is the code
on clicked theObject
if the name of theObject is equal to "title_search" then
set repeat_num to 0 as integer
repeat
set repeat_num to repeat_num + 1
if repeat_num is 1 then
set dialog_text to "Type the title of the song that you want to play."
else
set dialog_text to "Your search turned up 0 results. Try again?"
end if
repeat
set the_dialog to (display dialog dialog_text default answer ¬
the_song buttons {"Search", "Cancel"} default button 1)
set the_song to the text returned of the the_dialog
if the_song is not "" then exit repeat
end repeat
tell application "iTunes"
set fi_value to fixed indexing
set fixed indexing to true
set the matching_tracks to (every track of library playlist 1 whose name contains the_song) as list
--if there's only one match, it is played
if the (count of matching_tracks) is 1 then
set my_track to item 1 of matching_tracks
exit repeat
--if there are more than one matches...
else if the (count of matching_tracks) > 1 then
--creates a variable containing info about each matching track
repeat with i from 1 to the (count of matching_tracks)
set track_name to the name of item i of matching_tracks
if the artist of item i of matching_tracks is not "" then
set track_artist to the artist of item i of matching_tracks
else
set track_artist to "Unknown"
end if
if the album of item i of matching_tracks is not "" then
set track_album to the album of item i of matching_tracks
else
set track_album to "Unknown"
end if
set track_info to i & ". " & track_artist & " - " & track_name & " (" & track_album & ")" as string
if i is 1 then
set matching_track_display to (track_info) as list
else
set matching_track_display to matching_track_display & track_info
end if
end repeat
--allows user to choose which matching track to play
set the_track to {choose from list matching_track_display with prompt ¬
"Your search turned up " & number of items in matching_tracks & " results. Please specify which track you want to play."} as string
if the result is "false" then
set fixed indexing to fi_value
return
end if
--finds which track to play
set ascii_bounds to {48, 49, 50, 51, 52, 53, 54, 55, 56, 57} as list
set the_number to ""
repeat until the (ASCII number of the first character of the_track) is not in ascii_bounds
set the_number to the_number & character 1 of the_track
set the_track to (characters 2 thru -1 of the_track as string)
end repeat
set my_track to item the_number of matching_tracks
exit repeat
end if
end tell
end repeat
tell application "iTunes"
play my_track
set fixed indexing to fi_value
end tell
tell application "Finder" to set the visible of every process whose name is "iTunes" to false