Skip to main content
Inspiring
October 17, 2022
Question

Is it possible to load the clipboard with text from a script

  • October 17, 2022
  • 3 replies
  • 436 views

I have a script that exports images at different sizes and depending on the name it will write to text document a path to that image. So Example.jpg is located in Server-1/A-F or Server-1/G-K etc. What I would like to do is instead of writing that to a text file, would be to load it to the clipboad so I could paste it in an email, is this possible? 

This topic has been closed for replies.

3 replies

rob day
Community Expert
October 17, 2022

Hi @davidn5918184 , I use these 2 functions for getting and setting the clipboard. So assuming you have an image direct selected, this copies its file path to the clipboard:

 

/**
* Sets the clipboard to the provided string
* @ return void
*/
function setClipboard(s){
    var tf = app.activeDocument.pages[0].textFrames.add()
	tf.parentStory.texts[0].select();
    tf.parentStory.contents = s;
    tf.parentStory.texts.everyItem().select(SelectionOptions.REPLACE_WITH)
	app.copy()
    tf.remove()
}

/**
* Gets the clipboard text contents
* @ return the clipboard‘s text as a string 
*/
function getClipboard(){
    var tf = app.activeDocument.pages[0].textFrames.add()
	tf.parentStory.texts[0].select()
	app.paste()
	var cb = tf.parentStory.contents.toString();
    tf.remove()
    return cb
}

 

Inspiring
October 17, 2022

Thank you. The difference is I want to load the clipboard with a string, but this is interesting, app.copy().  Could you put a varible in there?

Brainiac
October 17, 2022

@davidn5918184,

 

Yes, you could probably use app.copy() to change from writing to a text file to getting that info copied to the clipboard.

If you have a single image selected you could try this..

 

//Copy Full Path
app.menuActions.itemByID(132623).invoke();

 

Regards,

Mike

 

Brainiac
October 17, 2022

@davidn5918184,

It would be helpful if you posted the code for the script you're using...

 

"I have a script that exports images at different sizes and depending on the name it will write to text document a path to that image".

 

It seems like it would be an easy change from writing to a text file to getting that info copied to the clipboard.

 

Regards,

Mike

 

 

 

Loic.Aigon
Brainiac
October 17, 2022