Skip to main content
_AWID_
Inspiring
January 22, 2025
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
January 23, 2025

Here's how to get the clipboard contents.

Translate
Legend
January 22, 2025

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
January 22, 2025

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

 

Translate
Robert at ID-Tasker
Legend
January 22, 2025

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

 

Translate
_AWID_
_AWID_Author
Inspiring
January 22, 2025

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

Only this workaround is possible?

Translate
Robert at ID-Tasker
Legend
January 22, 2025

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