I’m making a script that tells the user what songs are being listening to over iTunes (either by the user or by others connected to your shared library). Only problem is, I’m getting a runtime error message about variable types that I can’t figure out.
Here’s the code (the error is about 12 lines down):
--hardcode the directory of your iTunes music library to 'dir'
set dir to "~/Music/iTunes/'iTunes Music'" as string
--take output of all open system files and search for only audio in dir
set shell_script to "readout= lsof +D" & " " & dir & " | grep [mp3,m4p,m4a]; echo -n $readout;"
set song_list to do shell script shell_script as list
set result to do shell script shell_script as list
if song_list is {} then
set message to "There are no songs being listened to right now." as string
else
set song_list_index to 0 as integer
set message to "Songs people are listening to:" as string
--THE ERROR MESSAGE POINTS TO 'length' IN THE LINE BELOW
repeat while song_list_index is less than or equal to the length of song_list
--for each list item, trim the .xxx file suffix, then the everything until the file name off the string
set suffix to characters (-4) thru end of item song_list_index of song_list as string
set item song_list_index of song_list to trim_line(item song_list_index of song_list, suffix, 1)
set song_list to trim_line(item song_list_index of song_list, "/", 0)
song_list_index = song_list_index + 1
end repeat
end if
display dialog message & return & song_list buttons {"OK"} default button 1 with icon 1
--lightly modified version of apple's trim subroutine
on trim_line(song_list, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is 0 then
repeat while song_list contains trim_chars
try
set song_list to characters (x + 1) thru -1 of song_list as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in 1 then
repeat while song_list ends with the trim_chars
try
set song_list to characters 1 thru -(x + 1) of song_list as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return song_list
end trim_line
Here’s the error message I get: Can’t make Can’t make number into a some object. *Note: the Can’t make Can’t make isn’t a typo.
Can someone give me a hand?
Gracias!