In and Out

I haven't made a KM macro from scratch in a while and I am forgetting how to take text in, manipulate it, and paste the changed text back out to where it came from. Any clarification would help at this point.

I am using a Typinator script to pull results for my calendar using icalbuddy. Problem is, I don't like the way icalbuddy formats the text output and the creator of icalbuddy hasn’t shown any interest in revising his script for a long time so, it is what it is. I am trying to solve the problem using a KM macro.

To do this I need to understand something that is, as Jimmie Buffet once said, so simple it has plumb evaded me. KM has a copy command and a copy to named clipboard command (and others of course). But then using an option-x keystroke will also cut (copy) and ... I think I can do all this with key commands on the text that will be on the clipboard - and then paste back the results.

This is the basic idea, I want to take this;

Mon, Jan 28:
(------------------------)
:white_check_mark: VA imaging
2:00 PM - 3:00 PM

And turn it into this;

Mon, Jan 28: 2:00 PM - 3:00 PM :white_check_mark: VA imaging

This is not too hard to do using keystroke to go to the end of a line, copy, paste, up arrow, repeat, down arrow, etc. It will normally have several items separated by a space so I will have to use some sort of a loop but, first things first. How to 1) copy the text block 2) apply all the changes to what I have copied to that captured text block, and 3) paste my newly formatted results back where the macro was triggered.

Thanks.

ADDED: I just got it working using the cut and paste in real time on the document. I asked the question to understand how I could do the following on the KM clipboard and then paste the results back to the document.

This method works pretty well. I have it parse an entry and then delete to the beginning of the next entry. Hitting the key trigger again is no big deal although using the clipboard and looping might be an easier way.

In case anyone is wondering, using the ...

Type the ⇧⌘Right Arrow Keystroke
Type the ⇧⌘Left Arrow Keystroke

... together ensures I select the entire line as the preceding line will likely leave my cursor not at the lines beginning and a simple down arrow to select the line needs the whole line.

Type the Forward Delete Keystroke
Type the ⇧⌘Right Arrow Keystroke
Type the Right Arrow Keystroke
Type the Tab Keystroke
Type the Down Arrow Keystroke
Type the Down Arrow Keystroke
Type the Down Arrow Keystroke
Type the ⇧⌘Right Arrow Keystroke
Type the ⇧⌘Left Arrow Keystroke
Type the ⌘X Keystroke
Type the Up Arrow Keystroke
Type the Up Arrow Keystroke
Type the Up Arrow Keystroke
Type the ⇧⌘Right Arrow Keystroke
Type the Right Arrow Keystroke
Type the ⌘V Keystroke
Type the Tab Keystroke
Type the Down Arrow Keystroke
Type the Down Arrow Keystroke
Type the ⇧⌘Left Arrow Keystroke
Type the ⇧⌘Right Arrow Keystroke
Type the ⌘X Keystroke
Type the Up Arrow Keystroke
Type the Up Arrow Keystroke
Type the ⇧⌘Right Arrow Keystroke
Type the Right Arrow Keystroke
Type the ⌘V Keystroke
Type the Down Arrow Keystroke
Type the ⇧⌘Left Arrow Keystroke
Type the ⇧⌘Right Arrow Keystroke
Type the Delete Keystroke
Type the Forward Delete Keystroke
Type the Forward Delete Keystroke
Type the Forward Delete Keystroke
Type the Forward Delete Keystroke

Preparation :

Type the ⌘Right Arrow Keystroke to make sure your cursor is at the end of the line.

Type the ⌘Left Arrow Keystroke to make sure your cursor is at the beginning of the line.

Tips:

  • Regular Expression is good to manipulate text with a specific pattern(Date、Time、and so on)

Start work:

  • choose the line and delete it (with Shift⇧、Command⌘、Arrows、Delete)
  • delete line break
  • delete words not letters (with Option⌥)

I do appreciate the idea, but what I am still trying to understand is how it works with KM when I want to capture the whole text block and do all of this in KM against what is then on the clipboard and then, to paste back the results.

I could try putting the above lines in a repeat block and see how that works I suppose. I will try that next.

What I have posted does work. When I do this:

Type the ⇧⌘Right Arrow Keystroke
Type the ⇧⌘Left Arrow Keystroke

This method will select the entire line no matter where the cursor is. Remember, this is being set up to run by its self so I cannot make sure that the cursor is at the end or at the beginning - other than using the method I just mentioned.

The solution I posted works - as long as I don't have any calendar entries with notes, location or URL. Most of these entries only use Event Name, Time of the event, and date of the event so this works well with my example. It is entirely icalbuddy that sets this formatting. I only came to this solution to have each entry on a single line without the separating line because I don't like how icalbuddy leaves the formatting.

This

Type the ⇧⌘Right Arrow Keystroke
Type the ⇧⌘Left Arrow Keystroke

can't select the entire line or text block, it choose the entire content in a file .

KM do things in macOS way.

Mac keyboard shortcuts - Apple Support

Well, not trying to be argumentative here, but that method does work for me. I wrote it by testing it with NVAlt. Then I put it into a KM macro. It works quite well in NVAlt, Nisus, and in Scrivener.

I did it using trial and error. Without that method and having different lengths for event titles, I could never be certain of selecting the whole line.

Although, perhaps we are saying the same thing - at least, it seems so. When this;

Type the ⇧⌘Right Arrow Keystroke

Takes you to the end of the line, and then this;

Type the ⇧⌘Left Arrow Keystroke

takes you to the beginning of the line. Either way, now the entire line has been selected.

Then, I can either cut the line for pasting somewhere else, or delete it. But, it does work for me.

ADDED: I am having trouble thinking like a programmer. I am using an UNTILL block for my above code. I was trying it with a repeat block but this needs a specific number of a count to repeat and the results will vary in their count.

Using the UNTILL block I have several choices. What I am looking for is something to indicate that the end of the text block has been reached.

I was thinking of using some phrase to test how this works like "endofhteline". Maybe I am not yet understanding how this is supposed to work because I am trying;

 "if all of the following are true"
"The Text" endoftheline
"Contains" contains endoftheline

I am not understanding how to word this so that when the UNTILL block hits the word "endoftheline". It will stop the macro - or at least that part of the macro.

Any tips there?

Thanks.

Can you show your KM macro ?
My English is not good enough and I may misunderstand what you are really want to do with your text/clipboard content in KM.

You may need this:

Removing line and paragraph breaks from the clipboard - Questions & Suggestions - Keyboard Maestro Discourse

This is how it works:

There is a way to export and share the macro - but I cannot remember how to do this. If you remind me how then I will do this.

I will post again the steps I took with the addition of one extra step, a copy to the clipboard step.

I did this as I am still trying to understand how to stop the macro. If I place the term "endoftheline" at the same distance below the text to run the macro on then the macro should copy this text and according to what I am understanding using UNTILL, this should run UNILL the system clipboard contains "endoftheline". Except that so far this is not working.

Testing with this, starting on the left margin on first line:

Mon, Jan 28:
(------------------------)
• VA imaging
2:00 PM - 3:00 PM

Mon, Jan 28:
(------------------------)
• VA imaging
2:00 PM - 3:00 PM

Mon, Jan 28:
(------------------------)
• VA imaging
2:00 PM - 3:00 PM

Mon, Jan 28:
(------------------------)
• VA imaging
2:00 PM - 3:00 PM

endoftheline

This is my KM macro:

    Execute Actions Until Conditions Met
    Type the Forward Delete Keystroke
    Type the ⇧⌘Right Arrow Keystroke
    
    Type the ⌘C Keystroke
        — Comment: I am adding the copy 
command here so that, in theory, this first line of 
each new section will be on the clipboard. I was
 thinking that when it does this with the line that
 contains endoftheline it would then match the
 condition to stop the macro. But so far, this is
not working.
         
    Type the Right Arrow Keystroke
    Type the Tab Keystroke
    Type the Down Arrow Keystroke
    Type the Down Arrow Keystroke
    Type the Down Arrow Keystroke
    Type the ⇧⌘Right Arrow Keystroke
    Type the ⇧⌘Left Arrow Keystroke
    Type the ⌘X Keystroke
    Type the Up Arrow Keystroke
    Type the Up Arrow Keystroke
    Type the Up Arrow Keystroke
    Type the ⇧⌘Right Arrow Keystroke
    Type the Right Arrow Keystroke
    Type the ⌘V Keystroke
    Type the Tab Keystroke
    Type the Down Arrow Keystroke
    Type the Down Arrow Keystroke
    Type the ⇧⌘Left Arrow Keystroke
    Type the ⇧⌘Right Arrow Keystroke
    Type the ⌘X Keystroke
    Type the Up Arrow Keystroke
    Type the Up Arrow Keystroke
    Type the ⇧⌘Right Arrow Keystroke
    Type the Right Arrow Keystroke
    Type the ⌘V Keystroke
    Type the Down Arrow Keystroke
    Type the ⇧⌘Left Arrow Keystroke
    Type the ⇧⌘Right Arrow Keystroke
    Type the Delete Keystroke
    Type the Forward Delete Keystroke
    Type the Forward Delete Keystroke
    Type the Forward Delete Keystroke
    Type the Forward Delete Keystroke
    UNTILL Any of the following are true
    System Clipboard
    Contains
    endoftheline

Without trying to make it repeat it works great on each individual calendar.

KM is expert at repetitive work.
What you are doing manually, let KM do it automatically.

Here is how I use KM to duplicate current line:

I use Control+D to do "Type this keystroke then type that keystroke" thing, this is the method.

I think we are not communicating very well here. I apologize that my meaning has been unclear.

What I just showed you is what I am having KM do for me. I am not doing this manually.

The only problem that I am still having is how to stop the macro with some sort of a trigger using a text field to trigger it to stop.

There is no "stop the macro" thing. If you didn't trigger the KM Trigger, KM will do nothing.

We are not on the same page here. Thanks.

Using a conditional statement (Until, If, Then, Else) is what I was meaning. So yes of course you can set up a condition to stop the macro.

I am waiting for @peternlewis to chime in.

I think I know what you wanna to do, finally.
You just need to add workflow (if、switch、) into your macro, but there is no "stop the macro" thing.

No Action equals to your "stop the macro".

Friend, it’s a matter of communication here. If you use an the UNTIL statement as I have said many times that I am using here, that statement says to;

execute actions until conditions met:

So, you enter your conditions, create a loop, until

conditions are met.

When conditions are met,

it stops the actions

Another way of saying this is that it,

it stops the macro.

So yes, this is stopping the macro. Arguing about the exact meaning of a phrase in "take no further action" or "stopping the macro" seems non productive and a bit pointless to me.

I have to get back to work.

Talk is cheap. What we say isn't describes accurately the exact requirement. This is why I take several pictures of my macros and paste it here.

Why not take a screenshot of your macro or export it and then figure out how to improve it?

@levelbest, I apologize if your question has been answered, but after skimming the many posts, it was not clear to me.

Also not clear to me is the exact workflow you would like.
So, here's the workflow I will use, and you can tell me if it works for you or not:

  1. Manually Select Text to be processed
  2. Trigger KM Macro
    • Extract desired text and reformat
    • Replace Selected Text with this new format

Here's an example macro to get you started:

Source Text Selected

image

Example Results

image


Extract and Reformat Text [Example]

Extract and Reformat Text [Example].kmmacros (2.5 KB)

image


Questions?

I figured it out. This thread was never about my not being able to select, copy, and move the text around. But for some reason, I kept getting advice about that. This thread was getting a little toasty, kept going round in circles, so I dropped it. In the mean time, I figured it out.

This thread was about learning how to do the work in a variable as opposed to just using keystrokes in what I call "real time". In the end, I went with that ("real time") and it works perfectly now.

Then I had some problems learning how to set the macro to stop. I wanted this to work on one - or a dozen entries, so I wanted it to trigger on the last phrase that I use just for that purpose.

For some reason, selecting some text, using the copy keystroke "should have" meant that SystemClipboard would have held that copied value. But using SystemClipboard that now contains the copied text value - did not stop the macro when it should have.

What I had to do was to copy the text (that I used to stop the macro when it was at the end), assign it to a variable, and then use the variable to meet the same condition as the copied text, which stopped it.

The other thing that I had to figure out was, If I put the "copy text to variable" near the top as I had been doing, just because it stopped it - did not prevent it from finishing the entire macro before stopping.

So the final solution was to make it select and copy the text and set the variable to compare just at the end. Now, it works great.

I love what can be done with this app.

Thanks.

You may need “cancel this macro” action.

A macro should be logical and orderly,and with no effect to other macros and system clipboard(unless you intend to).For example, every “Insert text by pasting” action followed by “Delete the current clipboard” action,so the macro as a whole will do nothing to system clipboard.