Pasting truncated clipboard string

I have this big number that I am trying to break down and past in multiple fields. I am looking for a way of running the macro after I have the number on my clipboard and entering the first 2 digits on the first field, the next 4 digits on a separate field and the following digits are a date so they must be modified to include “/” characters.

For example, I copy the number “88003017072020654”, then I would need the macro to enter 88 on the first text field, 0030 on the second text field, and then “17/07/2020” on the third field.

I’ve figured out the ${!clipboard} command is to input text but I have yet to figure out how to modify pre input.

You should be able to do that with split. Search “split” in the forums and there are some examples to work with.
You can also manipulate the data using XRun and using a script

Without criteria split can not work the user is not explaining what it has to do and without precise rules can’t separate the text

It always splits at the same amount of digits, for eample the first part is always the first 2 digits the second is always the next 4.

This can easily be done with PowerShell by splitting by string by length and adding the “/” for the 3rd field. Not sure about JS code though

I found a way of splitting it into bits od pairs using the code below

return ${Variable}.split(/(.{2})/).filter(x => x.length == 2);

However, turns out he structure separation is in 4,2,5,8 character amounts

Solved by me with a better solution

Log

[status]

Playing macro Extract_Part_Text

[info]

Executing: | store | 88003017072020654 | MyVar |

[info]

Executing: | executeScript_Sandbox | return ${MyVar}.substr(0,2); | MyResult1 |

[info]

Executing: | executeScript_Sandbox | return ${MyVar}.substr(2,4); | MyResult2 |

[info]

Executing: | executeScript_Sandbox | return ${MyVar}.substr(6,2); | MyResult3 |

[info]

Executing: | executeScript_Sandbox | return ${MyVar}.substr(8,2); | MyResult4 |

[info]

Executing: | executeScript_Sandbox | return ${MyVar}.substr(10,4); | MyResult5 |

[info]

Executing: | echo | {MyResult1} \n\n {MyResult2} \n\n {MyResult3}/{MyResult4}/${MyResult5} | #shownotification |

[echo]

88

0030

17/07/2020

[info]

Macro completed (Runtime 2.36s)

Macro Code

{
  "Name": "Extract_Part_Text",
  "CreationDate": "2020-6-28",
  "Commands": [
    {
      "Command": "store",
      "Target": "88003017072020654",
      "Value": "MyVar"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${MyVar}.substr(0,2);",
      "Value": "MyResult1"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${MyVar}.substr(2,4);",
      "Value": "MyResult2"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${MyVar}.substr(6,2);",
      "Value": "MyResult3"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${MyVar}.substr(8,2);",
      "Value": "MyResult4"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return ${MyVar}.substr(10,4);",
      "Value": "MyResult5"
    },
    {
      "Command": "echo",
      "Target": "${MyResult1} \\n\\n ${MyResult2} \\n\\n ${MyResult3}/${MyResult4}/${MyResult5}",
      "Value": "#shownotification"
    }
  ]
}

Image

Thank you very much, this works perfectly :grin:

1 Like

Nice work newuserkantu!

1 Like