Ensure the Path String in the Clipboard Starts with “/”

I am trying to create a macro that will paste a Finder path into the "Go To Folder..." menu after I copy it manually. Very simple and easy. However, the issue I am having is with the program SLACK. Unfortunately Slack will not let a user paste a Finder path starting with a "/" so people have to delete this character when sharing.

Here is what I am trying to do:

  1. I copy a Finder path in Slack or email
  2. Search to see if there is a "/" in the front of the clipboard text
  3. If there is no "/" add it to the clipboard and paste it in the Go To Folder menu.

I just can't figure out how to check the clipboard. I tried to convert the text to a variable, still not working yet.

Any help would be much appreciated. :slight_smile:

Hi @Xacto,

It's very simple with Keyboard Maestro.

This macro will remove the "/" for you if your SystemClipboard starts with "/".

SystemClipboard.kmmacros (2.0 KB)

Thanks so much, however I am looking for the opposite - add the “/“ to the front if it is missing.

Thanks

I'm sorry, I misread.

This is easier:

SystemClipboard.kmmacros (1.9 KB)

3 Likes

Wow thanks. I thought it would be very complex. You make it so easy! :pray:

1 Like

Hey Brian,

Things are often that way with Keyboard Maestro, but the opposite is also pretty common.

Kudos – you did a good job of describing your task and making it easy for people to help you.

Here's how I'd probably approach this job:

RegEx – Ensure a Path String starts with “-” ⇢ Negative Lookahead & Positive Lookahead v1.00.kmmacros (6.5 KB)
Keyboard Maestro Export

Whitespace often slips unannounced into copied text – hence the trim action.

A regex with a negative-lookahead-assertion instead of a more formal IF structure.

@cdthomer – this is a case where I personally would probably use a N.L.A – and the macro also incorporates other techniques discussed in this thread:

RegEx question: how to search for white space repetitions (1 tab and 1 new line)

TMTOWTDI

-Chris

2 Likes

Note that there is a Clipboard condition, which you can use directly instead of the Text condition and the SystemClipboard token:

image

Not that it makes much difference.

3 Likes

Makes sense, thanks for tagging me on this one. I like the TMTOWTDI link too, until I clicked on it I was scratching my head :sweat_smile:

1 Like

Thanks!
I was looking for it did not see it. I think I was probably looking for SystemClipboard instead of Clipboard.

1 Like