obsidian.nvim
obsidian.nvim copied to clipboard
ObsidianPasteImg <name> and "There is no image data in clipboard" on mac
π Describe the bug
After taking a screenshot on mac (cmd-shift-5) and saving it to the clipboard I try to "paste" to nvim/obsidian note but getting: "There is no image data in clipboard" message. The image is in the clipboard - can paste to other applications.
Config
{
"epwalsh/obsidian.nvim",
ft = "markdown",
version = "*",
lazy = true,
dependencies = {
-- Required.
"nvim-lua/plenary.nvim",
},
opts = {
workspaces = {
{
name = "personal",
path = "~/Documents/Notes",
},
},
picker = {
name = "telescope.nvim",
},
notes_subdir = "0_Inbox",
templates = {
subdir = "Templates",
date_format = "%a, %b %e, %Y",
time_format = "%H:%M",
},
-- Specify how to handle attachments.
attachments = {
img_folder = "Assets/Images", -- This is the default
img_text_func = function(client, path)
path = client:vault_relative_path(path) or path
return string.format("", path.name, path)
end,
},
completion = {
-- Set to false to disable completion.
nvim_cmp = true,
-- Trigger completion at 2 chars.
min_chars = 2,
},
new_notes_location = "0_Inbox",
note_id_func = function(title)
local suffix = ""
if title ~= nil then
suffix = title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower()
else
for _ = 1, 4 do
suffix = suffix .. string.char(math.random(65, 90))
end
end
return suffix .. "-" .. tostring(os.time())
end,
},
},
Environment
nvim --headless -c 'lua require("obsidian").info()' -c qNVIM v0.9.5
Build type: Release
LuaJIT 2.1.1713517273
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.5/share/nvim"
Run :checkhealth for more info
Obsidian.nvim v3.7.5 (df0c5cce68a02481c0d40d1b25433e368fd12a5a)
Status:
β’ buffer directory: nil
β’ working directory: /Users/adam/.config
Workspaces:
β active workspace: Workspace(name='personal', path='/Users/adam/Documents/Notes', root='/Users/adam/Documents/Notes')
Dependencies:
β plenary.nvim: 8aad4396840be7fc42896e3011751b7609ca4119
β nvim-cmp: 97dc716fc914c46577a4f254035ebef1aa72558a
Integrations:
β picker: TelescopePicker()
β completion: enabled (nvim-cmp) β refs, β tags, β new
all sources:
β’ nvim_lsp
β’ luasnip
β’ buffer
β’ nvim_lua
β’ path
Tools:
β rg: ripgrep 14.1.0
Environment:
β’ operating system: Darwin
Config:
β’ notes_subdir: 0_Inboxn
Is the image a PNG? I believe at the moment only PNG format is supported.
It seems it also stores some metadata in the few first bytes and it seems it's this for the screenshot: 0xC2 0xAB 0x63 0x6C 0x61 0x73 0x73 0x20 0x50 0x4E 0x47 0x66 0xC2 0xBB 0x3A 0xC2 0xAB 0x64 0x61 0x74 0x61 0x20
The rest is a png (or PNGf to be precise). Here's how pillow handles that:
def grabclipboard():
if sys.platform == "darwin":
fh, filepath = tempfile.mkstemp(".png")
os.close(fh)
commands = [
'set theFile to (open for access POSIX file "'
+ filepath
+ '" with write permission)',
"try",
" write (the clipboard as Β«class PNGfΒ») to theFile",
"end try",
"close access theFile",
]
script = ["osascript"]
for command in commands:
script += ["-e", command]
subprocess.call(script)
im = None
if os.stat(filepath).st_size != 0:
im = Image.open(filepath)
im.load()
os.unlink(filepath)
return im
But I think stripping first few bytes would work as well (rather that calling osascript) pypaperclip also seems to be able to do it https://github.com/asweigart/pyperclip
I'm happy to review a PR for making this functionality more robust
I'm certainly not skilled enough to create the PR but hopefully somebody will pick it up :)
@RetroTechCorner did you brew install pngpaste? I was getting the same error until I installed that.
Not sure if I should be creating a new issue for this or not as it is related.
I can copy (using cmd + c) a PNG image while inside Finder and use the ObsidianPasteImg to paste it into a README or other .md file, but instead of seeing the actual image, I just see the PNG file icon, rather than the actual image itself:
If you want me to create a new issue for this, as it is a different but related issue, let me know and I'd be happy to do so.
I'm running into the original issue. I get "There is no image data in the clipboard".
I've confirmed that I've copied a png, and I've run brew install pngpaste and confirmed it's in my Path (I can run pngpaste on the command line and get the usage suggestions back)
Let me know if you have any suggestions or if there's any other info I can provide to help debug this!
I'm running into the original issue. I get "There is no image data in the clipboard".
I've confirmed that I've copied a png, and I've run
brew install pngpasteand confirmed it's in my Path (I can run pngpaste on the command line and get the usage suggestions back)Let me know if you have any suggestions or if there's any other info I can provide to help debug this!
What version are you using? Is it the latest commit or the latest release? I had the same issue while using the latest release. Updating to the latest commit by removing the version = * entry from the plugin config solved this issue for me.
Not sure if I should be creating a new issue for this or not as it is related.
I can copy (using
cmd + c) a PNG image while inside Finder and use theObsidianPasteImgto paste it into a README or other .md file, but instead of seeing the actual image, I just see the PNG file icon, rather than the actual image itself:
![]()
If you want me to create a new issue for this, as it is a different but related issue, let me know and I'd be happy to do so.
@Mo0rBy have you managed to solve this issue? I'm running into this issue too and I'm struggling to find a fix for it. I believe this might be related to pngpaste itself because it reproduces not only when running ObsidianPasteImg, but when running pngpaste dummy.png in the terminal directly as well.
Not sure if I should be creating a new issue for this or not as it is related. I can copy (using
cmd + c) a PNG image while inside Finder and use theObsidianPasteImgto paste it into a README or other .md file, but instead of seeing the actual image, I just see the PNG file icon, rather than the actual image itself:![]()
If you want me to create a new issue for this, as it is a different but related issue, let me know and I'd be happy to do so.
@Mo0rBy have you managed to solve this issue? I'm running into this issue too and I'm struggling to find a fix for it. I believe this might be related to
pngpasteitself because it reproduces not only when runningObsidianPasteImg, but when runningpngpaste dummy.pngin the terminal directly as well.
I've managed to get it working. My solution was that instead of pressing cmd+c in Finder to open the image in Preview and then press cmd+c in Preview.
@mccuna thanks for the followup! I hadn't tried to paste an image since commenting, but it's now working for me (my lazy lock file is pointed at commit ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b)
