Let's say I have a variable that contains a list of URLs I want to do something with, a few at a time. Is this the most efficient way to do that? I'm sure I must have missed something simpler along the way. In particular, the Search and Replace actions (in the purple group) seem like a long-winded way to remove a line from a variable, mid-process.
Think of it like working your way through a box of index cards. You could take the first card (or 3 cards) out, use them, discard them, then go back to the box -- that's your approach above, always referring to the frontmost card(s). Or you could flick through the box leaving your finger in to keep your place every time you stop to process - that's the indexed approach I'm suggesting.
Both approaches are valid in different situations. When you are only using a list (array) once like here then removing items is good if that's supported. But KM doesn't seems to have a simple, native, way of "popping" items from lists/arrays, which is why I'm suggesting using an index.
Glad to know I'm not a total dunce, and that this does require a bit of thought!
Your macro works great! I think I understand your logic, but I'm trying to get my head around the use of square brackets and and the inclusion of the separator here:
Presumably the square brackets refer to a line in an array, like [1], [2], [3], and [4] do when accessing coordinates from a token or variable, but what I don't get is this is no longer a multi-line variable, so... How does that work and why does ,KMSEP, need to be included explicitly when the rest of that entry (the URL itself) doesn't?
You can access elements by index, using [aNumber] -- so accessing element 3 is [3]
The default item delimiter is , but if you are using something else you put it after the ] -- if we were using a .-delimited array, accessing element 3 would be [3].
You can't use Return as an array delimiter (here) so we replace every Return in the original list with something that will not be found in the text otherwise -- ,KMSEP,
So, after replacing the Returns in our list, accessing element 3 would be [3],KMSEP,
Putting that altogether with our variable name and the variable, Local_i, that holds our incrementing counter gets us:
%Variable%Local__URLs[Local_i],KMSEP,%
So each turn of the loop accesses "element i of the ,KMSEP,-delimited list held in Local__URLs".
One of the many posts I've read in an attempt to go more KM-native instead of snuggling up in my AppleScript security blanket. Meanwhile, @tiffle's trying to tempt me back to my old ways!
I very nearly piped up about using KM arrays with custom delimiters but then it got really complicated with CSVs, JSON, JavaScript... so it's nice to see the subject come up again but this time from the (busy) desk of @Nige_S
In my (limited) experience with Applescript, I've found KM to be a fair bit snappier. Doesn't matter a lot of the time, but I've often wondered why that is. Could be just UI interaction that's given me that impression, as that's mostly what I've used AS for.