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 Jun 2, 2012, 11:27 PM   #1
fhill2
macrumors newbie
 
Join Date: May 2012
iteration of a list in applescripts

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.
fhill2 is offline   0 Reply With Quote
Old Jun 3, 2012, 02:14 AM   #2
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: 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
kryten2 is offline   0 Reply With Quote
Old Jun 3, 2012, 10:41 AM   #3
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by kryten2 View Post
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/apples...-loop-examples

It's the third result googling for: applescript loop. The first two results are also worth reading.
chown33 is offline   0 Reply With Quote
Old Jun 4, 2012, 02:02 AM   #4
fhill2
Thread Starter
macrumors newbie
 
Join Date: May 2012
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!
fhill2 is offline   0 Reply With Quote
Old Jun 4, 2012, 09:04 AM   #5
Red Menace
macrumors regular
 
Join Date: May 2011
Location: Littleton, 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
__________________
MacBook Pro / OS X Mavericks (10.9.2) / Xcode 5.1 / [and various (much) older stuff keeping dust off the shelves]
Red Menace 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


All times are GMT -5. The time now is 05:08 PM.

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

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