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 6502
 
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 Yosemite (10.10) / Xcode 6.1 / RubyMotion FTW
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

Similar Threads
thread Thread Starter Forum Replies Last Post
Graphics Performance Hit with Every Iteration of Mavericks Prodo123 OS X Mavericks (10.9) 7 Aug 29, 2013 03:06 AM
What's Your Favourite Iteration Of OS X? Goftrey OS X 15 Feb 21, 2013 11:17 AM
AppleScripts snippets thread moonman239 Mac Programming 1 Jan 14, 2013 11:37 PM
Why the next iteration of the mini will NOT have a Retina display brig2221 iPad 25 Oct 26, 2012 01:38 PM
Most consistent way of referring to iTunes playlists in Applescripts fhill2 Mac Programming 0 Jun 22, 2012 07:57 PM

Forum Jump

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

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

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