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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Transfer an app from iTunes to iPhone 4 buggsy2 iPhone Tips, Help and Troubleshooting 0 Jan 3, 2011 04:20 PM
Unable to set encrypted passowrd in iTunes 10.0.1.22 addy23 iPhone 0 Oct 28, 2010 02:03 AM
Unable to drag and drop from itunes 9.2 to Toast Qwest905 Mac Applications and Mac App Store 3 Jul 18, 2010 02:48 PM
setTitle - trying to set title of an NSWindow to contents of NSTextfield - failing glossywhite Mac Programming 2 Sep 8, 2009 04:29 PM
Unable to sync after changing from Movie to TV Show nomad01 iPod 0 Oct 7, 2008 05:41 AM


All times are GMT -5. The time now is 08:35 AM.

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

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