Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 8, 2007, 08:53 AM   #1
John Mosby
macrumors newbie
 
Join Date: Feb 2007
Location: Denison, Texas
Send a message via AIM to John Mosby
Applescript - Unable to set variable value from iTunes to BBedit

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

========================================
__________________
John Mosby
John Mosby is offline   0 Reply With Quote
Old Feb 8, 2007, 08:56 AM   #2
wrldwzrd89
macrumors G4
 
wrldwzrd89's Avatar
 
Join Date: Jun 2003
Location: Solon, OH
Quote:
Originally Posted by John Mosby View Post
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.
__________________
iMac Intel (Rev H, 27"), 1TB HDD, 16GB RAM, 10.8.4
wrldwzrd89 is offline   0 Reply With Quote
Old Feb 8, 2007, 09:03 AM   #3
John Mosby
Thread Starter
macrumors newbie
 
Join Date: Feb 2007
Location: Denison, Texas
Send a message via AIM to John Mosby
Thanks! I changed the "to" to "on", but the problem remains the same.
__________________
John Mosby
John Mosby is offline   0 Reply With Quote
Old Feb 8, 2007, 03:57 PM   #4
lancestraz
macrumors 6502a
 
lancestraz's Avatar
 
Join Date: Nov 2005
Location: RI
What are you trying to do in the two sub routines "fix_filename" and "text_to_list"?
lancestraz is offline   0 Reply With Quote
Old Feb 8, 2007, 09:52 PM   #5
John Mosby
Thread Starter
macrumors newbie
 
Join Date: Feb 2007
Location: Denison, Texas
Send a message via AIM to John Mosby
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.
__________________
John Mosby
John Mosby is offline   0 Reply With Quote
Old Feb 10, 2007, 11:49 PM   #6
Mekanik561
macrumors newbie
 
Join Date: Feb 2007
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
Mekanik561 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Applescript to open itunes at 7am and set radio to send to airplay speaker gordo5150 Mac Programming 1 Apr 23, 2014 12:48 PM
String and variable concatenation in AppleScript tekboi Mac Programming 6 Apr 15, 2014 01:37 PM
Applescript newb: declaring a variable in another script. Vanilla Face Mac Programming 2 Jan 5, 2014 07:39 PM
How to set environmental variable? hajime Mac Basics and Help 3 Sep 28, 2013 09:33 PM
AppleScript: Set variable to every XML element of a given name moonman239 Mac Programming 13 Jan 2, 2013 02:55 PM

Forum Jump

All times are GMT -5. The time now is 06:36 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC