A multifunction paste macro (for clipboards, mail variables, case changes, URLs)

triggers
mail_apple
variables
email
clipboard

#1

This is a macro designed to:

  • paste from a selected clipboard (e.g. Clipboard 1, Clipboard 3 etc)
  • paste a range of Clipboards, with a seperator you choose (useful for spreadsheets)
  • paste the most recent Clipboard in UPPERCASE, lowercase or Title Case
  • paste variables from Mail (Sender's Name, email address, Subject, Mail text and much more)
  • paste a URL.

All of these are triggered by a key sequence vvX

X is a variable or 'switch' which governs what will be pasted. So for example, the sequence vve pastes the email address taken from an email, while vvn pastes the sender's name.

In turn, vv2 pastes the second clipboard, vv3 pastes the third and so on.

The sequence vvp pastes the clipboard in uppercase, while vvl will paste in lowercase.

NOTE:

  • A separate macro is needed to copy the variables from a mail. I have published an example here: “Get all Mail info from Tokens” Macro
  • You will need a macro that copies your URLs and puts them into the Variable %URL%.

Paste selected elements.kmmacros (31 KB)


MODERATOR'S NOTE:
There are a number of variations/enhancements to this macro presented below, including this update posted by the OP. So you may want to scroll down to view these variations.



How to check if nothing was copied (make a markdown bolding macro)
Macro to harvest an individual's (current) LinkedIn info for CRM
#2

This is really great. Thank you for posting. Gives me some ideas!


#3

This is really great. Thank you for posting. Gives me some ideas!

Good—I look forward to seeing how you and others might extend and improve it!


#4

PSA: This trigger conflict’s with the {clip} expansion from Typinator’s Plain Clipboard Text predefined Set. I removed it, as this one is much more useful.


#5

To customize it for my use, I've:

  • Removed the mail bits and added some text filters
  • Reorganized the actions into one Switch/Case action
  • Added a Delete Past Clipboard 0 Action after each manipulation

PSA: these macros should live in a Macro Group that excludes Keyboard Maestro. Triggering while editing actions can be catastrophic.


Multifunction Paste.kmmacros (30.6 KB)


#6

I like the quote and parentheses ideas. Perhaps that could be extended to HTML and/or Markdown tags as well?

Thanks also for the Sentence Case option!


#7

Yes those would be good useful too. I tried using symbols as a trigger but no dice. That would open up a lot of options.


#8

This is indeed a handy macro. :+1:

Here's my minor contribution.

This prompt is presented when the trigger ends with a "?":
;vv?

which allows the user to see and select the paste options.

My trigger:
;vv[\w|\?]

Insert the magenta Action "IF: Show Prompt IF "?" for Trigger" between the "Isolate Trigger" and the "Switch of Variable" actions (and don't forget to change your trigger to allow a "?"):

The Default Value list for theTrigger is:
1__Past Clipboard 1|r__r - Range of Clipboards|l__l - lowercase|u__u - UPPERCASE|t__t - Title Case|s__s - Sentence case|q__q - "wrap in quotes"|p__p - (wrap in parentheses)

For those of you unfamiliar with this form, it allows you to show one text string but return a different string:
Text to RETURN__Text to SHOW

So you simply separate the text to return from the text to show by two underscores ("__")

If you want, you can download this ACTION.
Note: When you import an Action, it will immediately put the Action after the current selected Action in your macro.

####Download ACTION:
IF Trigger is ? Action -- JMichaelTX.kmactions (1.9 KB)


#9

What symbols did you try?

It should work with any unicode character as long as you allow for it in the trigger RegEx, like I did with the “?”:
;vv[\w|\?]


#10

I didn’t realize I had to add the non-alpha characters to the trigger. Seeing your reply above tipped me off. Updating my macro now. Thanks!


#11

Updated macro using symbols instead of letters:


Multifunction Paste.kmmacros (47.6 KB)



#12

Sorry, I have provided a poor example of RegEx:

It is better written as:
;vv[\w\?]

The square brackets [ ] indicate that one of any of the characters in the brackets will be matched. So we don’t need the vertical bar | for alternates.


#13

Thanks, updated.


#14

Even simpler, this covers most symbols (doesn't catch | or ^ and some others) but those could be added manually:


#15

I've added ;vvd as a trigger now ("d" for "digit," though that makes little mnemonic sense):


#16

I have another switch for this macro so that I can paste numbers cleanly.

Copied credit card numbers often have spaces and telephone numbers can include brackets and hyphens, all of which can cause confusion when posted to a web form.

Similarly, copied numbers which have comma separators in the format xx,xxx.yy can be awkward when posting to spreadsheets.

This switch removes everything except digits and the decimal point.

(Europeans may want to put a comma in place of the point!)

The RegEx for removing cruft is [^0-9\n\r\.] (This means: remove everything that is not a digit, not a line-break, and not a decimal)

I adapted the idea from the people at Ergonis, who produce Typinator.


#17

You make this statement:

But then you counter it with this:

Your RegEx does indeed leave LF and CR characters in the string, so that is what is pasted. Easy to fix, of course:
[^0-9\.]

Why would you want to leave LF and CR in the string?

If you do, then this might be better:
[^0-9\R\.]
since \R includes all forms of new line characters, including LFCR.


#18

My aim was to keep digits and the decimal, along with line feeds and I don’t see a fault in my statements or the RegEx (though I see your “\R” suggestion is more elegant).

The reason I want to include the line feed in my expression is because I need to copy columns like this into a spreadsheet:

1,234.56
78,910.11
12,131,415.16


#19

Just thought I would mention that I have a new switch 'q' to the macro on my system.

This allows me to use vvq to paste text as a quote in Markdown format, like this:

Clipboard pasted as a quote in Markdown format

It should handle multiple paragraphs as well...

Warning – these are actions and will import directly into the macro currently being edited.

Paste quote.kmactions (5.6 KB)

image