I'd like some advice on using variables/clipboards. I just got a macro working, but it seems awkward so I'd appreciate any pointers on how to do things better.
This macro determines the longest line in whatever text is selected. I ended up using 3 variables and 2 clipboards. Is this just how KM macros are, or is there a better way?
There's always a different way, sometimes a better way. But, so long as it gets you the right result, the best way is the way that you can easily understand -- because it's you who will need to make changes later!
And as what you easily understand will change as you get more experience with KM, your macros will change too.
Here's another way of doing "Longest Line" -- two variables and only the System clipboard:
The easiest way to do it is to hit the Share button in the toolbar—it will do all the work for you, including disabling the macro. Or if you want to get fancier, you can install a macro to post in a really nice manner. In fact, that's what I used for the macro below.
As for your macro, you will need some number of variables, but you shouldn't need any clipboards. Here's one solution that works:
If you post here often enough, you'll find that there are roughly 15,235 ways to solve any given problem, as evidenced by @Nige_S and my solutions above :).
I haven't downloaded your macro but from the screenshot I can ask: why are you using a named clipboard Temporary at all? Instead, you can just use the Set Variable action to set a variable called localTemporary to %Variable%localClipboardLine%.
Named clipboards are good for all kinds of items (images, formatted text etc) and they persist like global variables do, but you seem to be using just plain text so a run-of-the-mill variable will do nicely for that.
If I loaded your macro onto my Mac maybe I'd see a reason to use named clipboards - but I suspect not
I like this version for Find longest line, but I tried to use the macro for uploading posts to this forum and expected it to post here. Instead, it had me post a new topic which seems to contradict the macro notes. It also disabled the Find longest line macro
Anyway, regarding this Find longest line macro, I think I understand everything except the penultimate action to Set system clipboard to %Variable%Variable Name% -- I don't understand what that's for. I noticed that if I disabled it, the macro worked fine.
That can happen if you don't give it enough time to finish. What should happen is that the post opens, then everything in it is cut to the clipboard. At that point, you can either open a new topic and paste it in, or visit an existing topic and paste it in.
Whoops. I think my intent was to write your variable back to the clipboard, but it got left in generic form. If you wanted it on the clipboard, just change %Variable%Variable Name% to %Variable%local_theLine%. But not required at all unless that's what you want.