I am getting:
and am wondering why…
set theFolderList to {"music1", "music2", "music3", "music4"}
set thisFolder to 0
tell application "Finder"
repeat (count theFolderList) times
set thisFolder to thisFolder + 1
set theLocation to "mydmg:music:" & (item thisFolder of theFolderList)
set theMusic to get every file of folder theLocation
tell application "iTunes"
set thisSong to 0
repeat (count theMusic) times
set thisSong to thisSong + 1
add item thisSong of theMusic to library playlist 1
end repeat
end tell
end repeat
end tell
Thank you!
The problem is with the Finder. By default, it returns objects that other applications don’t understand (instead of the usual alias). You can use as alias list
in the Finder to get the desired results; However, there is currently a bug with that when getting an alias with only one item.
Try something like this:
set theFolderList to {"music1", "music2", "music3", "music4"}
repeat with thisFolder in theFolderList
tell application "Finder"
try
set theMusic to every file of folder "mydmg:music:" & (item thisFolder of theFolderList) as alias list
on error
-- Workaround for a bug where `alias list` doesn't return a list when there is only one item
set theMusic to every file of folder "mydmg:music:" & (item thisFolder of theFolderList) as alias as list
end try
end tell
tell application "iTunes"
count theMusic
repeat with i from 1 to result
add (item i of theMusic) to library playlist 1
end repeat
end tell
end repeat
Ah, ok… Thank you very much Bruce.
Curious, is there a benefit to doing the repeats the way you did them vs. how I did originally?
the “thisFolder in theFolderList”, and the “1 to the result”?