telesoho / vscode-markdown-paste-image

Smartly paste for Markdown.
MIT License
135 stars 41 forks source link

Latest changes broke image pasting on macOS #58

Closed marcinjahn closed 2 years ago

marcinjahn commented 2 years ago

Since the last update I cannot paste images into markdown anymore on macOS Monterey. I see the following logs:

[12-26 17:27:01] Cannot found script for darwin
[12-26 17:27:01] getClipboardContentType
[12-26 17:27:01] null

A couple days ago it worked perfectly fine.

vezaynk commented 2 years ago

Mea culpa. I have accidentally removed support for it in #54 by removing this codepath.

It will be fixed soon.

vezaynk commented 2 years ago

@marcinjahn

You can test the fix by running

git clone https://github.com/knyzorg/vscode-markdown-paste-image
cd vscode-markdown-paste-image
npm i
npx vsce package
code --install-extension ./vscode-markdown-paste-image-0.15.2.vsix
marcinjahn commented 2 years ago

@knyzorg The error is a bit different now:

12-26 20:03:01] "vscode-markdown-paste" is now active!
[12-26 20:03:01] No scipt exists for darwin
[12-26 20:03:01] Clipboard Type:
[12-26 20:03:01] -1
[12-26 20:03:04] /Users/marcin/.vscode/extensions/telesoho.vscode-markdown-paste-image-0.15.2/res/mac.applescript: /Users/marcin/.vscode/extensions/telesoho.vscode-markdown-paste-image-0.15.2/res/mac.applescript: cannot execute binary file
vezaynk commented 2 years ago

What happens when you try running osascript /Users/marcin/.vscode/extensions/telesoho.vscode-markdown-paste-image-0.15.2/res/mac.applescript? Do you encounter the same error?

marcinjahn commented 2 years ago
~/.vscode/extensions/telesoho.vscode-markdown-paste-image-0.15.2/res
❯ osascript /Users/marcin/.vscode/extensions/telesoho.vscode-markdown-paste-image-0.15.2/res/mac.applescript

~/.vscode/extensions/telesoho.vscode-markdown-paste-image-0.15.2/res

It executes properly (I passed no arguments like in your example).

vezaynk commented 2 years ago

@telesoho Do you have a macbook you can test with? I'm not sure why this is happening. It seems to work from CLI but not from the extension.

marcinjahn commented 2 years ago

@knyzorg I think there is some issue with the choice of executor. I logged the ${shell} ${options.join(" ")} line of the runCommand function. I got sh /Users/marcin/.vscode/extensions/telesoho.vscode-markdown-paste-image-0.15.2/res/mac.applescript /Users/marcin/tmp/2021-12-26-20-20-59.png. It should use osascript instead of sh I guess.

vezaynk commented 2 years ago

@marcinjahn I did some changes. Can you pull and try again?

marcinjahn commented 2 years ago

@knyzorg Yes, that works. Actually, I started creating a branch with that fix, but you were faster. Also, you fixed more switch cases than that single place.

marcinjahn commented 2 years ago

@knyzorg Even though the functionality works, the log is a bit confusing:

[12-26 20:37:32] "vscode-markdown-paste" is now active!
[12-26 20:37:32] No scipt exists for darwin
[12-26 20:37:32] Clipboard Type:
[12-26 20:37:32] -1

"No script exists"?

vezaynk commented 2 years ago

The way this extension is designed, it expects to have multiple scripts for each OS.

One for

The only one we have for Mac is pasting images. So the way it works is it fails detect the clipboard type for Mac and falls back to attempting to extract plain text, which if fails, runs the paste image script.

I'm not very good with Macs, so someone will need to write the other scripts.

marcinjahn commented 2 years ago

Yeah, I see that in code. I'm not good neither, today was the first time I saw actual AppleScript code :)

vezaynk commented 2 years ago

The fix has been merged

JeffersonDing commented 2 years ago

Having the same issue on macOS Monterey on version 0.18.6. Copy past image works as expected but download image results in output

[04-01 00:24:05] "vscode-markdown-paste" is now active!
[04-01 00:24:05] No scipt exists for darwin
[04-01 00:24:05] Clipboard Type:
[04-01 00:24:05] -1