Not sure if this is a bug or not, but I can't get the 'Return' token to work when trying to use a new-line-delimited variable as an array.
I've tried with 'set variable to text':
%Variable%myFakeArray[1]Return% returns the entire variable (not just the first line).
%Variable%myFakeArray[2]Return% returns an empty variable.
%Variable%myFakeArray[1]%Return%% returns the full variable, with "Return%" tacked onto the end.
With "Set variable to calculation":
myFakeArray[1]Return, the 'Return' gets colored red (as does, apparently, any delimiter item after the closing bracket.
Maybe I'm just doing it all wrong but I'm unclear as to what exactly I'm doing wrong...
Instead of the comma you can also use a custom delimiter of your choice. But I wouldn’t use a newline character (even if the tokens would work) because there are many kinds of them: Return, Line Feed, CRLF, …
Several of my macros use a similar technique to replace newline characters with other delimiters. It works very well for preparing text for easier search and replace within KM. I never use a comma as a delimiter, though, because a comma can easily be part of one or more of my entries. Even if you don’t anticipate a comma being part of your text, it’s a good idea (in my opinion) to use a multi-character delimiter that has effectively no chance of being in the text (e.g., ::: or &&&). These also have the advantage that they are easy to spot in the converted list.
Also, keep in mind that you can reverse the process after changes are made, and replace the custom delimiters with newline characters if you’d like to keep the original format intact (but with the changes that the macro made).
So, to return to your initial question about the %Return% token — and if you don’t want to replace it by some other char (or by a sequence of characters, in case this works) — I don’t know why the %Return% token isn’t accepted as delimiter. Might be a limitation of the variable notation syntax, or a bug. (@peternlewis?)
I couldn’t make it work either (But I didn’t spent too much time on it.)
That also brings up the question of whether array delimiter notation recognizes regex. For example, would %Variable%MyArray[3]\n% make any sense to KM?
I believe you can only use printable characters as the delimiter.
I could NOT find this so stated in the KM Wiki, so @peternlewis will have to confirm/correct.
Yeah only using printable characters as the delimiter would make sense! Not sure how I got it in my head that Return would work. I ended up using one of Tom's suggestions of just using Search and Replace, which works quite nicely! I save the altered one as a new array as I still need the original with new lines for some For Each actions - though maybe I could transition to Substrings instead?
You cannot generally have tokens within tokens (about the only exception to this is within nested brackets, such as: %Calculate%1+CHARACTERS(%LongDate%)%).
So the text between the ] and % is plain text. Even \n will not work.
As suggested, the technique to use is to replace the return with something that is plain text and unique (so generally not a comma). For example ",KMSEP,".
Search and replace \n with ,KMSEP, and then use [index],KMSEP,% at the end of your token.
Anything that is plain text and unique is fine. Verbosity is hardly an issue since it only appears twice and you should never see it within the structure anyway.
I believe it's mainly because applescript uses french quotes - «» - to denote raw apple event code, which could conceivably break some stuff when you try and process it with applescript (my understanding is that a good bit of KM's back-end involves applescript).
I doubt this because I use the « symbol all the time in my AppleScript code in Script Debugger 7. SD7 uses it as a marker for a particular comment line.