How to get a file from a link starting with file://

{
  "com.apple.webarchive as propertyList": {
    "WebSubresources": [
      {
        "WebResourceURL": "file:///var/folders/f_/v7vs50394951q1rw3s7mt_ww0000gn/T/com.eusoft.eudic.QuickLook/_mdx_1_1310462979/img/zzz_popcorn.jpg",
        "WebResourceMIMEType": "image/jpeg",
        "WebResourceResponse": {},
        "WebResourceData": {}
      }
    ],
    "WebMainResource": {
      "WebResourceURL": "file:///Applications/Eudb_en.app/Contents/Library/LoginItems/LightPeek_en.app/Contents/Resources/Html/",
      "WebResourceFrameName": "",
      "WebResourceMIMEType": "text/html",
      "WebResourceData": {},
      "WebResourceTextEncodingName": "UTF-8"
    }
  },
  "public.rtf as string": "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2638\n\\cocoatextscaling0\\cocoaplatform0{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}\n{\\colortbl;\\red255\\green255\\blue255;\\red224\\green224\\blue224;}\n{\\*\\expandedcolortbl;;\\cssrgb\\c90196\\c90196\\c90196;}\n\\deftab720\n\\pard\\pardeftab720\\partightenfactor0\n\n\\f0\\fs26\\fsmilli13333 \\cf2 \\expnd0\\expndtw0\\kerning0\n\\outl0\\strokewidth0 \\strokec2 }",
  "public.rtf as data": "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2638\n\\cocoatextscaling0\\cocoaplatform0{\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;}\n{\\colortbl;\\red255\\green255\\blue255;\\red224\\green224\\blue224;}\n{\\*\\expandedcolortbl;;\\cssrgb\\c90196\\c90196\\c90196;}\n\\deftab720\n\\pard\\pardeftab720\\partightenfactor0\n\n\\f0\\fs26\\fsmilli13333 \\cf2 \\expnd0\\expndtw0\\kerning0\n\\outl0\\strokewidth0 \\strokec2 }",
  "public.html as string": "<img src=\"file:///var/folders/f_/v7vs50394951q1rw3s7mt_ww0000gn/T/com.eusoft.eudic.QuickLook/_mdx_1_1310462979/img/zzz_popcorn.jpg\" class=\"\" style=\"caret-color: rgb(230, 230, 230); color: rgb(230, 230, 230); font-family: Helvetica, &quot;Lucida Grande&quot;, Lucida, Verdana, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;\">",
  "public.html as data": "<img src=\"file:///var/folders/f_/v7vs50394951q1rw3s7mt_ww0000gn/T/com.eusoft.eudic.QuickLook/_mdx_1_1310462979/img/zzz_popcorn.jpg\" class=\"\" style=\"caret-color: rgb(230, 230, 230); color: rgb(230, 230, 230); font-family: Helvetica, &quot;Lucida Grande&quot;, Lucida, Verdana, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;\">",
  "public.utf8-plain-text as string": "",
  "public.utf8-plain-text as data": "",
  "com.apple.WebKit.custom-pasteboard-data as string": "\u0001\u0000\u0000\u0000\u0007\u0000\u0000\u0000\u0001file://\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
  "com.apple.WebKit.custom-pasteboard-data as data": "\u0001\u0000\u0000\u0000\u0007\u0000\u0000\u0000\u0001file://\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
}
<img src="file:///var/folders/f_/v7vs50394951q1rw3s7mt_ww0000gn/T/com.eusoft.eudic.QuickLook/_mdx_1_1310462979/img/zzz_popcorn.jpg" class="" style="caret-color: rgb(230, 230, 230); color: rgb(230, 230, 230); font-family: Helvetica, &quot;Lucida Grande&quot;, Lucida, Verdana, sans-serif; font-size: 13.333333015441895px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;">

I'm trying to extract links from both texts and neither seems to work

These two texts are obtained from the two macros above
I'll start with @Nige_S's method, which I can set up myself.
Thank you.

1 Like

Can I ask a another question? How do I set the condition to trigger this json action.

What if the clipboard contains?

How do I set the condition to trigger this json action.

This one ?

You should be able to choose any KM trigger, but I may not have fully grasped the context or question.


What if the clipboard contains?

Not sure that I've followed the question yet ... (我英文水平有限)

My English is poor.
I mean how do I set the if condition to execute the json action?
Because I don't copy images every time

Could you give us an example of the context ?

You want to launch it only when the clipboard contains an image ?

Or only when it doesn't ?

Something else ?

Yes, that is, use it when the clipboard is invalid

If it's plain text, I can just use the clipboard to paste it without executing the action via json script, otherwise I'll get a messy code.

So I only need the script when I can't use the clipboard

Screen Recording 2022-09-27 at 17.23.55.2022-09-27 17_43_39

So you want to test whether the clipboard contains HTML content ?

Usually the clipboard contains multiple "pasteboard items", each in a different format.

Typically, if the clipboard contains an HTML pasteboard item, it may also contain a plain text pasteboard item.

We can't, therefore, test for whether the clipboard "is" plain text – it's usually multiple, as you can see by using the clipboard viewer too.

I think you will need to formulate for yourself exactly what clipboard conditions you are hoping to detect.

So you want to test whether the clipboard contains HTML content ?

Yes

If it's plain HTML, how should it detect

how do I set the condition?

plain = ?

It would be unusual for the clipboard to only contain html.

If the clipboard cannot be used directly, how should it detect

Can it only be tested manually?

be used directly for what, specifically ?

When I paste in notepad, it is blank

OK, have you experimented with Clipboard conditions in a Keyboard Maestro "If" action ?

Screenshot 2022-09-27 at 11.06.29

It doesn't work, because I'm copying a link with the file:/// format, which is not an image, but it can be recognized by the script you gave me, as I think you probably know.

All I can think of that the moment, without test material (samples of the kind of material that you are copying) to hand is a variant of the script I gave you in which you:

  1. trap the return string which it generates
  2. branch on that with an IF THEN ELSE action

Capture public.html pasteboard item as pasteable plain text.kmmacros (8.7 KB)

1 Like

Thank you very much.
It may still not work for me.
The solution I can think of now is to go through the script you gave me and after getting a string of characters, add the if condition and if it contains the file:/// character, proceed to the next action, otherwise just paste

This is probably the best way I can think of.

Thanks again.

1 Like

This is the best way I found it. By filtering, getting a “UFFFC” character (Unicode Character 'OBJECT REPLACEMENT CHARACTER') and then judging it by if statement. But I can't modify your script, so I have to use this clumsy way, but it may be the only way

Filter Clipboard Macro (v10.1.1)

Filter Clipboard.kmmacros (8.4 KB)