Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fhill2

macrumors newbie
Original poster
May 9, 2012
19
0
I have a list full of iTunes data I need to return in Max for Live, using this script:

tell application "iTunes"
set theartist to artist of item 1 of selection
set thealbum to album of item 1 of selection
set thebpm to bpm of item 1 of selection
set thecomment to comment of item 1 of selection
set thelist to theartist & " " & thealbum & " " & thebpm & " " & thecomment as list
end tell


What I need to do is iterate each item in the list and return it into the applescripts window (this is how I send it to Max).
How can I accomplish this?
Thanks.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Code:
tell application "iTunes"
	set theartist to artist of item 1 of selection
	set thealbum to album of item 1 of selection
	set thebpm to bpm of item 1 of selection
	set thecomment to comment of item 1 of selection
	set thelist to theartist & " " & thealbum & " " & thebpm & " " & thecomment as list
	repeat with i from 1 to number of items in thelist
		set this_item to item i of thelist
		-- insert actions here
	end repeat
end tell
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
Code:
tell application "iTunes"
	set theartist to artist of item 1 of selection
	set thealbum to album of item 1 of selection
	set thebpm to bpm of item 1 of selection
	set thecomment to comment of item 1 of selection
	set thelist to theartist & " " & thealbum & " " & thebpm & " " & thecomment as list
	repeat with i from 1 to number of items in thelist
		set this_item to item i of thelist
		-- insert actions here
	end repeat
end tell
Or maybe:
Code:
	repeat with this_item in thelist
		-- insert actions on this_item here
	end repeat
See:
http://www.devdaily.com/apple/applescript-for-loop-while-loop-examples

It's the third result googling for: applescript loop. The first two results are also worth reading.
 

fhill2

macrumors newbie
Original poster
May 9, 2012
19
0
I've tried the repeat loop with this command: return this_item, and still get a list in MAX. Maybe you cannot iterate a list through the return command?
Full script:

tell application "iTunes"
set theartist to artist of item 1 of selection
set thealbum to album of item 1 of selection
set thebpm to bpm of item 1 of selection
set thecomment to comment of item 1 of selection
set thelist to theartist & " " & thealbum & " " & thebpm & " " & thecomment as list
repeat with i from 1 to number of items in thelist
set this_item to item i of thelist
return this_item
end repeat
end tell


And another quest, how would I enclose each item in the list with quotation marks, so I can accurately process the list when it's in MAX.
I would believe saving each variable as string would work?, i tried, and it didn't :(

Thanks for the help!
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
Your list item (thelist) only has one item (the string you set it to), so can you clarify exactly what you are wanting to output? If you are wanting to do something with each of the items you are getting from iTunes, you can do something like:

Code:
set theList to {}
tell application "iTunes"
	set the end of theList to (artist of item 1 of selection)
	set the end of theList to (album of item 1 of selection)
	set the end of theList to (bpm of item 1 of selection)
	set the end of theList to (comment of item 1 of selection)
	repeat with anItem in theList
		set thisItem to quote & (contents of anItem) & quote
		log thisItem -- do something with thisItem, this example just logs it
	end repeat
end tell
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.