Skip to main content
_AWID_
Inspiring
Jan 22, 2025 12:47 PM UTC
Question

Save the contents of the clipboard to a variable

Hello

 

I haven't found an easy solution here to work with the clipboard contents by placing it in a variable, to modify it. Using paste() it will be placed in the document. But first I want to format it and delete some of its parts.

 

Regards

14 replies

Kasyan Servetsky
Legend
Jan 23, 2025 8:25 AM UTC

Here's how to get the clipboard contents.

Translate
Legend
Jan 22, 2025 5:59 PM UTC

On some platforms, clipboard operations are available from the platform scripting system.

var text = app.doScript("the clipboard as text",ScriptLanguage.APPLESCRIPT_LANGUAGE);

On other platforms, search recommends to use the HTMLFile object.

https://stackoverflow.com/questions/19696308/how-can-i-use-clipboard-in-vbscript

Translate
Robert at ID-Tasker
Legend
Jan 22, 2025 6:01 PM UTC

Yes, on Windows, in VB6 it's built-in. 

 

Translate
Robert at ID-Tasker
Legend
Jan 22, 2025 12:49 PM UTC

Create TextFrame, paste clipboard, read contents - do what you need. 

 

Translate
_AWID_
_AWID_Author
Inspiring
Jan 22, 2025 12:51 PM UTC

(...and after all delete the TextFrame.)

Only this workaround is possible?

Translate
Robert at ID-Tasker
Legend
Jan 22, 2025 12:54 PM UTC

It should be possible in official / latest version of JS - but InDesign's version is limited and outdated - and I'm not JS guy, sorry.

 

Translate