That's very cool, thanks for sharing. So doing something like
Might be a better choice for that sort of thing then.
That's very cool, thanks for sharing. So doing something like
Might be a better choice for that sort of thing then.
I haven't measured the overhead of shell vs AppleScript vs Javascript (hint: maybe you can do that) but if performance is an issue, as it is for me, shell is probably the best option.
I'm confused by the entire linked thread, as well as this new one—with array variables in Keyboard Maestro, why not just generate a random number and pick that random element of the array?
Random sentence.kmmacros (4.3 KB)
That seems to work fine, and avoids all the overhead of JavaScript, AppleScript, or the shell. But I must not be understanding something, or someone else would have suggested similar long before?
-rob.
Good point, but I have two reasons for doing it differently. 1) I originally wrote my solution long before KM supported custom delimiters in KM variable references; 2) My lines of data which I have to pick from randomly already consist of 8 items separated by commas.
But I see your point, and I should be able to adapt your solution now. Thanks for the good suggestion.
Thank you both, and my apologies. I don't know what has been happening, but for some reason, when I press reply quite often, it makes a new thread.
Even better for the AppleScript version would be
set lowNum to 1
set highNum to 10
return random number from lowNum to highNum
No need to make your own function when there's a built-in one.
And as a one-liner, avoiding the "Filter" and "Calculation" actions:
%Variable%Local_lines[RAND(1,LINES(%Variable%Local_lines%))]\n%
As demoed here.