PDA

View Full Version : Applescript - Unable to set variable value from iTunes to BBedit




John Mosby
Feb 8, 2007, 08:53 AM
I have been trying to hack a script. I am not an accomplished scripter
and I am in need of a script that will give me the Filename, Artist,
and Track Title saved to a text file. I have put together the
following script but it fails. The following never executes as far as
I can tell....

try
set track_info to this_track's name & tab & this_track's artist & tab &
fix_filename(this_track's location) & return
end try

therefore, there is never any text inserted into the open BBedit
window. In the Event Log the final message is "The variable track_info is not defined.". I think it may have something to do with the fix_filename subroutine. I'm not sure what is going wrong here, can someone help?
Thanks.

=============================================
tell application "BBEdit 6.5"
set d to make new document
set w to window of d
end tell

tell application "iTunes"
if kind of container of view of front window is not library or selection of front browser window is {} then
display dialog "Select some tracks in iTunes first." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end if

display dialog "Ready to copy filename, song title, and artist to BBedit window." buttons {"Cancel", "Proceed..."} default button 2

set sel to selection of front browser window

set old_fi to fixed indexing
set fixed indexing to true

with timeout of 3000 seconds
repeat with this_track in sel
if class of this_track is file track and this_track's location is not missing value then

try

set track_info to this_track's name & tab & this_track's artist & tab & fix_filename(this_track's location) & return
end try
end if


tell application "BBEdit 6.5"
select insertion point before character 1 of text window 1
set selection of text window w to track_info
end tell

end repeat
end timeout

set fixed indexing to old_fi

try
display dialog "That's All Folks!" buttons {"Thanks"} default button 1 giving up after 4
end try

end tell

to fix_filename(loc)
set theText to text 1 thru -((length of name extension of (info for loc)) + 2) of (last item of my text_to_list(loc as Unicode text, ":"))
display dialog theText

return theText
end fix_filename

on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD

return (theList)
end text_to_list

========================================



wrldwzrd89
Feb 8, 2007, 08:56 AM
I have been trying to hack a script. I am not an accomplished scripter
and I am in need of a script that will give me the Filename, Artist,
and Track Title saved to a text file. I have put together the
following script but it fails. The following never executes as far as
I can tell....

try
set track_info to this_track's name & tab & this_track's artist & tab &
fix_filename(this_track's location) & return
end try

therefore, there is never any text inserted into the open BBedit
window. In the Event Log the final message is "The variable track_info is not defined.". I think it may have something to do with the fix_filename subroutine. I'm not sure what is going wrong here, can someone help?
Thanks.

=============================================
tell application "BBEdit 6.5"
set d to make new document
set w to window of d
end tell

tell application "iTunes"
if kind of container of view of front window is not library or selection of front browser window is {} then
display dialog "Select some tracks in iTunes first." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
end if

display dialog "Ready to copy filename, song title, and artist to BBedit window." buttons {"Cancel", "Proceed..."} default button 2

set sel to selection of front browser window

set old_fi to fixed indexing
set fixed indexing to true

with timeout of 3000 seconds
repeat with this_track in sel
if class of this_track is file track and this_track's location is not missing value then

try

set track_info to this_track's name & tab & this_track's artist & tab & fix_filename(this_track's location) & return
end try
end if


tell application "BBEdit 6.5"
select insertion point before character 1 of text window 1
set selection of text window w to track_info
end tell

end repeat
end timeout

set fixed indexing to old_fi

try
display dialog "That's All Folks!" buttons {"Thanks"} default button 1 giving up after 4
end try

end tell

to fix_filename(loc)
set theText to text 1 thru -((length of name extension of (info for loc)) + 2) of (last item of my text_to_list(loc as Unicode text, ":"))
display dialog theText

return theText
end fix_filename

on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD

return (theList)
end text_to_list

========================================
I found a bug in fix_filename. Your definition starts with "to" instead of "on". It should be like text_to_list.

John Mosby
Feb 8, 2007, 09:03 AM
Thanks! I changed the "to" to "on", but the problem remains the same.

lancestraz
Feb 8, 2007, 03:57 PM
What are you trying to do in the two sub routines "fix_filename" and "text_to_list"?

John Mosby
Feb 8, 2007, 09:52 PM
fix_filename is supposed to return just the file name from the last entry in the list returned by text_to_list.

text_to_list will take the location of the file as a directory listing and place each directory in a list with the filename as the last entry.

Mekanik561
Feb 10, 2007, 11:49 PM
You're missing a "my"

set track_info to this_track's name & tab & this_track's artist & tab & my fix_filename(this_track's location) & return