Skip to main content
Inspiring
Oct 17, 2022 2:50 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

6 replies

rob day
Community Expert
Community Expert
Oct 17, 2022 6:48 PM UTC

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
}

 

Translate
Inspiring
Oct 17, 2022 7:04 PM UTC

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?

Translate
Legend
Oct 17, 2022 7:25 PM UTC

@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

 

Translate
Legend
Oct 17, 2022 5:09 PM UTC

@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

 

 

 

Translate
Loic.Aigon
Legend
Oct 17, 2022 2:59 PM UTC