Request :: additional action-result option(s) - 'append to variable'

I noticed today that steps would have been fewer if I could reach for one (or two ?) additional result use options in actions that offer this:

My request would be to add:

  • append results to variable, and
  • append results to variable as new line

This would be very helpful in macros which are mapping from one collection to another, for example:

  • from a list of Finder selection paths to tilde-abbreviated versions of those paths
  • from a list of Mail selections to a TaskPaper or Markdown text with subjects and links
  • from a list of text lines to Title Cased versions of the same lines

etc. etc.

2 Likes

And if append is available, then preprend could in some cases be useful as well.

2 Likes

This is pretty much why there is no "append". "with space", "with comma"? "with new line" - before or after the appending. Etc. There would have to be a whole sub-menu of extra options to catch just the common cases.

The same issue applies to selecting multiple clipboards and pasting them all when people request some sort of additional insertion between them. The one you want is probably not the same as the one anyone else wants.

What I may add is an Append Text to Variable action, rather than requiring Set Variable to Text and using the variable in the token. And as @JimmyHartington notes, then a Prepend will also be useful.

4 Likes

I would be thrilled if there was a new action called “Append Text to Variable”. I append text a lot for things like making logs, queueing up commands, etc. I understand Peter’s concern about the separation characters.

My view is KM shouldn’t put any separation characters in when appending/prepending. Anything fancy like that and I end up calling Shell functions anyway.

2 Likes

This already exists. Just use Set Variable and include the Variable token in the data field:

image

Um thanks, but as I said, I already append text to a lot of things, and that’s how I do it. Do you not see the value in an Append Text to Variable action? It would make my code shorter. Also, there’s a bit of a bug in your example. If MyVariable is empty, the code you gave will put an extra carriage return before the text in your action. So that’s not exactly an appending action in your example. I’m sure you can fix your example, but it would be clearer if there was a new action that did appending.

1 Like

It is not a bug; it is by design.
I take "append" to mean add something to something that already exists.
If you don't want the CR, then just remove it from the Set Variable action.

So, no, I personally do not see the value in having a separate "Append Text to Variable" action, since it can easily be achieved with existing Action.

The same approach is used in every programming language I have used:
x = x + "append this"

Here's how it's done now:

And here's (roughly, photo-edited) how it could look with a new action:

That's 22 saved characters per action ("%Variable%%%Variable%%"), times perhaps 20 append actions per macro, times hundreds of macros. And an enormous gain in clarity. If those numbers are accurate that would save me approximately 44,000 characters of typing. Maybe nobody else uses append as much as I do, but I'm entitled to say I would be thrilled to see a new action. But I expect to lose this fight. I understand the minimalist philosophy to KM. Even so, I'm sure we could make a list of KM actions that are redundant and only there for clarity and simplicity.

I hope I don't get banned for having a differing opinion. I love KM and use it a lot every day.

I'm not familiar with c++ but I just googled it and it allows string concatenation like this:

myvar+:="append this"

so I'm sure there are lots of languages that don't make you repeat "x" as you indicated in the last line of your post.

And for that reason I realize now it's actually 29 characters saved, not 22, in my example. I miscounted. The gain is 25% more than I estimated.

No problem with opinions or requests. Many new/changed features have been provided in response to user requests. It is not up to me -- @peternlewis will weigh how well it fits in with the KM design and the cost/benefit and respond accordingly.

No one would ever get banned for respectfully stating a requested feature.

I have noted this down, and it is possible I will some ways to append in a future version, either with explicit actions, or with additional output options.

Great, thanks. That gives me an idea, but it deserves its own topic.

What is the difference in KM between the AppleScript actions of "append results to variable" compared to "save results to variable"?

image

First time results,

second time resultsresults

third time resultsresultsresults

append adds the new value to the end of any existing value.
assign adds the new value to the end of a brand new empty string.