I seem to have issues working with lists and repeats here.
I have a variable called thisFolder, which contains a list of paths to the files in my table view.
For some reason I can’t get each file separately to do actions on them.
Here is my code:
set theseItems to thisFolder
(* if I have a dialog display the variable "thisFolder", it contains paths in the form
"Mac HD:Users:BS0D:Desktop:cfdt:mysample2.phpMac HD:Users:BS0D:Desktop:cfdt:my-sample.php" *)
repeat with i from 1 to count of theseItems
set thisitem to alias ((thisFolder as text) & (item i of theseItems))
--display dialog thisitem
set itemInfo to info for thisitem
if subOk and folder of itemInfo is true and package folder of itemInfo is false then
processFolder(thisitem, true)
else if (alias of itemInfo is false) and (the name extension of itemInfo is in extensionList) then
processItem(thisitem)
end if
end repeat
Then I get the following error :
I know of course there is something really wrong with my code here, but I cannot find the right syntax to get items separately for life of me !
I don’t understand why I can’t have each item separately and why in the error message I get the “M” at the end of the paths…
set theseItems to thisFolder
(* if I have a dialog display the variable "thisFolder", it contains paths in the form
"Mac HD:Users:BS0D:Desktop:cfdt:mysample2.phpMac HD:Users:BS0D:Desktop:cfdt:my-sample.php" *)
repeat with i from 1 to count of theseItems
try
set thisitem to (item i of theseItems) as alias
--display dialog thisitem
set itemInfo to info for thisitem
if subOk and folder of itemInfo is true and package folder of itemInfo is false then
processFolder(thisitem, true)
else if (alias of itemInfo is false) and (the name extension of itemInfo is in extensionList) then
processItem(thisitem)
end if
end try
end repeat
but it would be better to find the cause of the “M”-error
I need a clear explanation of what I can do here, because my problem is still not solved!
So what I do in my app is:
drop items on a table
display their paths (the path of each item in a different row)
get those paths and put them at the end a variable (called itemList{} or something)
→ then I want to process each item one by one, but I can’t seem to get the paths from that variable correctly, as the app gives me that error about the files not existing.
How would you go about doing that ? because my code, the one above, just does NOT work !
OK, I’m not on my mac right now (at work), but I’ll post my code tonight. It’s possible that the error occurs when I
get those paths and put them at the end of the variable …
Mind you, everything works perfectly when I follow those same steps in the other tabs of my app…
EDIT | actually I’m pretty sure that the error ocurrs when I try to set “theseItems” in the repeat procedure as follows:
set theseItems to thisFolder -- thisFolder contains all the paths, but I'm sure I need to do this differently
repeat with i from 1 to theseItems
set thisitem to --blah blah
-- blah blah
end repeat
-- here is the processing of my items
Well I think I should actually add something like :
set theseItems to thisFolder -- AS SOMETHING ? as string ? alias ? I don't know, these things confuse me!
Like I said, thisFolder contains paths in the following form :
I don’t know if this looks right, but thats what it says if I do a “display dialog thisFolder”
So first, is that what it should look like ?
And if so, what would be the best way to loop through those items?
Somewhere in your code before the display dialog statement you have a as text coercion, which coerces the path list to a string (text item delimiters are {“”} at that moment). This is the crucial line
I actually had to set theseItems to something other than thisFolder, I was calling the wrong variable (yeah, my script is long and tedious – about 2,000 lines, so in spite of commenting as much as I can, I kind of get confused)