Skip to main content
Participant
January 18, 2025
Question

Copy image to clipboard

  • January 18, 2025
  • 2 replies
  • 687 views

I am trying to write a script that coping the current page as an image to the clipboard.

My approach is to export the current page as a PNG image, and copy it with `nircmd clipboard copyimage` shell command.

I tried using `app.doScript` to run `nircmd`, but without success.

 

Note: Although I succeeded to do it with a bridge to photoshop:

var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = "var f = File('" + tempFile.fsName + "');" +
    "app.open(f);" +
    "app.activeDocument.selection.selectAll();" +
    "app.activeDocument.selection.copy();" +
    "app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);" +
    "app.close(f);" +
    "f.remove();";
bt.send();

but it opens the photoshop program, and it's annoying.

2 replies

m1b
Community Expert
Community Expert
January 19, 2025

Hi @yoav_4837 I have no experience with this specifically, but I wondered if it would work to re-import the image (particular formats might be better than others?) into Indesign and select/copy it via indesign (I mean copy the placed image, not the graphic frame, or try both). The question is, what exactly does it put on the clipboard and is it paste-able in other apps? Just wondering if you've tried it.

- Mark

yoav_4837Author
Participant
January 19, 2025

Yes, I have tried.
When I copy an Image from Indesign, it's available (as an image) only in the clipboard of the program. Outside it behaves like an empty clipboard.

Legend
January 19, 2025

InDesign keeps an own clipboard "scrap".

Clipboard externalization is a costly process, similar to an export multiplied by the number of supported flavours.

Not sure what triggers externalization, as your switching to WhatsApp (deactivating InDesign) apparently did not.

Or did you forget to activate WhatsApp?

 

Alternatively, ask the search engine or AI of your choice for a program in the environment of your choice (VBScript? Powershell?) to load the exported png file into the Windows clipboard.

When I did, the vbscript would use the user32 dll with commands such as OpenClipboard, while the Powershell script would rely on ImageMagick. I did not test either, typing this on a Mac.

For comparison, the Mac clipboard is directly scriptable.

Robert at ID-Tasker
Legend
January 19, 2025

Why do you need to have it in the clipboard? 

 

What is your end goal? 

 

yoav_4837Author
Participant
January 19, 2025

I want to paste the image outside of Indesign, like in WhatsApp, and send it to the customer. 

Robert at ID-Tasker
Legend
January 19, 2025

@yoav_4837

 

As @Dirk Becker suggested - doing it in the "native" scripting language - AppleScript on a Mac - VisualBasic on a PC - would be much easier.