If clipboard contains number between x and y perform an action?

hi there, i'm struggling to get this to work:

i have a workflow set up for a table of contents document where i'm copying a section number to the clipboard and want to check in which chapter this section is and then perform a different action/click depending on which chapter the section is located in.

So:
Chapter A
1
1.1
1.1.2
2
Chapter B
3
4.1
4.1.1
4.1.2
Chapter C
5
6

and so on. I managed to get it to work using a switch for the first chapter by using

if System Clipboard is < 3 ..... click on Chapter A

but now i would need a

if System clipboard >2 and <5 .... click on Chapter B

and can't figure out how to do this.

There is always only a single number in the clipboard (the section number) but sometimes it can be a two level number like 1.1.2 and that doesn't work with the > of course. I could use "starts with" in the condition but that won't work anymore when the section number is in the tens (10.1) so i need to figure out a way to combine conditions (like starts with 1 but is <10).

Little update, i managed to get it to work like this:

Screenshot 2020-08-19 at 16.58.39

any ideas if there is a more elegant, less laborious way? It would be nice if i could check for the condition in one go by using a list for example and then selecting the right image from a folder for the 'image found click'. So for each document where the structure is changing i coul just update the list for the 'find section' and put the new images for the Chapter click in a folder.

Assuming that all you want to compare is the first number (before any periods) on the clipboard, something like this might work:

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Switch Case Based on Number on Clipboard [Example]

-~~~ VER: 1.0    2020-08-19 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Switch Case Based on Number on Clipboard [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Macro Author: @JMichaelTX

This is just an example written in response to the below KM Forum Topic. You will need to use as an example and/or change to meet your workflow automation needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Topic Title: If clipboard contains number between x and y perform an action?

URL: If clipboard contains number between x and y perform an action?

Post Date: 2020-08-19
Posted By: mummel

wow, that was quick .. many thanks, i'll try it out tomorrow. i managed to get it all working with my convoluted method but your solution is what i was looking for :slight_smile:

@JMichaelTX again many thanks for this example which i've been playing around a bit. i have a solution for selecting the first two levels working now but i am struggling a bit now to adapt this to my needs.

The problem i'm having is with sections of the third level like 2.4.1. The easiest and most flexible way for me would be to generate one variable by level so i can use them to populate named clipboards which i can then use in various actions.

So for 2.4.1 i'd have the variables:

firstLevel=2
secondLevel=2.4
thirdLevel=2.4.1 (or original clipboard content)

i'm not sure i completely understand how the regex to variables work. When i try to use several regex conditions i get sometimes a second line under the All: field. Also i can't seem to find the variables in the variables menu which surely means they're not registered. I tried reading up on the variables and regex in KM but it's takin me a while to process and understand everything.

BTW. I am using a regex string i found on the web cause i couldn't figure out how to odify yours. The string shown in the screenshots works when i test them in a regex tester.

You're welcome, but you need to provide us with the COMPLETE requirements for what you want to do, rather than just giving us a small piece at a time. That wastes our time and yours.

So, please step back and provide us with:

  1. Real-world source text as you will be receiving it, that you want to process in some way.
  2. Real-world results of exactly what you want to get after processing.
  3. The rules for processing.

Please provide all example text in a Forum Code Block.

Finally, please read:
Tip: How Do I Get The Best Answer in the Shortest Time?

@JMichaelTX sorry if this wasn't clear, i was trying to keep it short.
what i am doing is building an automation system for a menu inside a webapp. basically checking for a number and finding it in a hierarchical tree menu. the webapp and it's contents are under NDA and posting my whole KM action here wouldn't make any sense since it's tied into specific window setups, local files etc. so i thought concentrating one just the part i need would be best.

in response to your questions:

  1. the text i will be processing are one to three level section numbers of the following format copied to the clipboard. only a single section number is copied to the clipboard and processed at a time and the section number can be any of the three following scenarios

1
1.1
1.1.1

but it also could be a double digit first or second level like for example

23.2.1 or 4.12.2


  1. i want to be able to determine how many levels there are and store the 3 parts of the number in 3 'level'-variables and copy them to named clipboards for further use so for the example number 23.2.1 those variables would be:

Level1=23 -> this hooks into my first action which is to check which chapter the section is in and click on the chapter header to open the subsections

Level2=23.2 -> this is used to find and either click on it or if there is a third level click the tree menu toggle switch to reveal the third level sections

Level3=23.2.1 -> used to find and click on this subsection

I will also need the following variables for other processing

secondLevel=true/false -> used for routing macros
thirdLevel=true/false -> used for routing macros


  1. i'm not sure what you mean with 'rules for processing' ?

i have done some further tests and it's working now but the only problem i have is that the named clipboards are not updating when i run the whole macro. i can see the All|1|2|3 variables updating in the KM interface when i run the macro so that part is working fine. i have deleted and recreated the named clipboards but i stil just can't get them to update. If i input the values manually in the named clipboards my whole chapter selection machine works fine now, it's just the named clipboards not updating at this stage.

Screenshot 2020-08-20 at 20.38.06

sectionFinder.kmmacros (4.2 KB)

BTW i'm on Catalina 10.15.6 .. not sure if that might be the problem with the clipboards not updating. KM v 9.0.6

the Display Clipboard macros also don't work, so this whole section does nothing:

Screenshot 2020-08-20 at 21.25.20

Thanks. That is a big improvement, although I'm still not clear on how you want to process the data.
Making a stab in the dark, I'm guessing that you want to do something, find or click on the TOC entry for a given chapter. You don't say how you will do this. Once you know it is Chapter 23, how do you use that in your Web App?

So here is a macro that will maybe help you get started.
One major point: You do NOT need, and should not use, Named Clipboards to store plain text data. Instead, use Global Variables .

Example Output

image

image

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Extract Section Parts and Process Based on Selection [Example]

-~~~ VER: 2.0    2020-08-20 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Extract Section Parts and Process Based on Selection [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Macro Author: @JMichaelTX

This is just an example written in response to the below KM Forum Topic. You will need to use as an example and/or change to meet your workflow automation needs.

HOW TO USE

  1. Select Section Number (like 23.2.5)
  2. Trigger this Macro

Macro Setup

  1. Move Macro to a Macro Group that will be Active when you need it
  2. CHANGE the ChapterList data in the below magenta-colored Action

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Topic Title: If clipboard contains number between x and y perform an action?

URL: If clipboard contains number between x and y perform an action?

Post Date: 2020-08-19
Posted By: mummel

@JMichaelTX sorry i don't know how else to explain but obviously you misunderstood, please have a look at the sectionFinder macro i attached, this works as intended and is exactly what i need except that the clipboards don't work.

i do not need or want to deal with a chapter list or chapter names. all i want i to do is to process a single number at a time and then run some different click actions on it, and everything is running fine except for the clipboards. i don't understand why i can't use named clipboards or why that doesn't work. i need to be able to paste the different parts of the section at different times in my macro to find the areas to click on .. isn't that exactly what named clipboards are for to have a repertoir of clipboards to paste from ???

here is the workflow again although at this point i really think i don't need to go into further details and can only repeat myself

  1. copy a section number to the clipboard
  2. disect it with regex to get the three levels and store 3 numbers
  3. use those numbers to populate the clipboard at different points of the macro flow

again, everything is working fine now except for the clipboards not updating, and if it was working like described here: https://wiki.keyboardmaestro.com/action/Set_Clipboard_to_Text then my problem would be solved and the macro finished and operational. But if there is a simpler/better way of getting the sections into the system clipboard i'm game of course but i thought using 3 clipboards would be the easiest way.

i already have this solution running for weeks for the first automated for the first two levels where i just need to click a couple of times for the third in the workflow but with this solution it will be completely automatic so i do not want or need to rethink what i'm doing here or have to explain the intricate details of my whole project from the top. you helped me solve the regex problem and now i'm just stuck because the named clipboards don't update and i can't think of another way of getting the three different numbers i already have sucessfully stored as intended into the clipboard at different point:

from number 23.3.1

level1 -> 23
level2 -> 23.3
level3 -> 23.3.1

and i don't mean a list like that but being able to pick one of these numbers and get them into the named clipboard(s) by constructing them out of the variables like i did in my attached macro. reading back the thread i also notice that i've explained this simple objective three times now and am really running out of ways to say it differently. it's really as simple as that.

so can you maybe answer this:

should the attached macro from my last post work and populate the three named clipboards ? i can't see how storing the result of

%Variable%firstLevel%.%Variable%secondLevel%

in a clipboard is any different to the example with the date in the wiki.
and could you maybe check if on your computer the clipboards update (just copy the number 23.3.1 to the clipboard and run the macro i attached) ? Do your clipboards change ?

You can, of course, use Named Clipboards if you wish for plain text, but there is no advantage.

Sorry, but I still don't have a clear understanding of your workflow, and I can tell you don't want to provide any more info. So, I'll leave you with this final Macro, and you can use it if you see fit.

To paste data into your Web App, you do NOT need a Named Clipboard,
Just use this Action to paste a KM Variable:

image

This macro is designed to work ONLY with the full section number, i.e. when you select ALL three levels, as in
23.3.1

It separates the levels as you have requested:

Example Output

image

image

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Extract Section Parts and Process Based on Selection Ver 3 [Example]

-~~~ VER: 3.0    2020-08-20 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Extract Section Parts and Process Based on Selection Ver 3 [Example] .kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Macro Author: @JMichaelTX

This is just an example written in response to the below KM Forum Topic. You will need to use as an example and/or change to meet your workflow automation needs.

HOW TO USE

  1. Select Section Number (like 23.2.5)
  2. Trigger this Macro

Macro Setup

  1. Move Macro to a Macro Group that will be Active when you need it
  2. CHANGE the ChapterList data in the below magenta-colored Action

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Topic Title: If clipboard contains number between x and y perform an action?

URL: If clipboard contains number between x and y perform an action?

Post Date: 2020-08-19
Posted By: mummel

thx again i'll give that a try but could you not, be it only for the sake of bug finding, just have answered the simple question at the end and try if on your computer your clipboards update ?

Sorry, I'm out of time for today. If you will use my macro then your issue will be irrelevant. There is no bug.

man what's your problem

should this Set Clipboard to Text action work ? simple yes or no question.
action