I've got the following code, which creates a filename, inserts a link to it at point, and should also save the current image in clipboard to disk at that filename/location. It used to work, but something broke recently, and I can't figure it out. The link is inserted correctly - the saving of the file is broken somehow.
Would greatly appreciate your help!
(defun my/org-screenshot ()
"Take a screenshot into a time stamped unique-named file in the
same directory as the org-buffer and insert a link to this file."
(interactive)
(setq filename
(concat
(make-temp-name
(concat (buffer-file-name)
"_"
(format-time-string "%Y%m%d_%H%M%S_")) ) ".png"))
(shell-command (format "powershell.exe -Command \"Add-Type -AssemblyName System.Windows.Forms; $clipImg = [System.Windows.Forms.Clipboard]::GetImage(); $clipImg.Save('%s')\"" filename))
(insert (concat "[[file:" filename "]]"))
(org-display-inline-images))
it doesn't render well in the comment, but the error I get (even when running it from powershell itself, but with powershell -Command...
) is:
At line:1 char:113 ... .Drawing.Bitmap = [System.Windows.Forms.Clipboard]::GetImage(); Syste ... ~ An expression was expected after '('.
This is the actual command being run:
powershell.exe -Command "Add-Type -AssemblyName System.Windows.Forms; $clipImg = [System.Windows.Forms.Clipboard]::GetImage^(^); $clipImg.Save('test.png')"
At line:1 char:92 + ... Windows.Forms; = [System.Windows.Forms.Clipboard]::GetImage(); .Save ... + ~ An expression was expected after '('. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : ExpectedExpression
powershell.exe
command with all its arguments in a Command window? Does it work there? I'm not sure howshell-command
does things on Windows, but the above should give you a clue about what's going wrong.