Highlighted

Javascript: Saving new file name as clipboard text

New Here ,
Aug 28, 2020

Copy link to clipboard

Copied

Hello. I currently work with quite a few InDesign template files (simply indesign files), which require me to relink pdf files to objects. I currently have a script that will save out the InDesign file to the specific location that needs to be saved to.

 

My current script looks like this:

var pt = app.paste();

if(app.activeDocument.saved == false) {
    app.activeDocument.save(new File("PATH" + pt + ".indd"));
 }

 

Thinking it through, I don't think the pasted text (app.paste) would work for the name, but I'm not sure if there's a way to grab the clipboard text, as I didn't see anything on the InDesign javascript scripting manual regarding this. Is something like this even possible/would there be any work arounds to being able to grab the text from the clipboard?

 

Thank you!

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

You need to paste it into something that you can then access. Calling paste on text makes a new textframe on your document and selects it. Thus, you can get it like this. I assume you have "PATH" defined somewhere else; in this case I saved to the Desktop. 

 

 

var doc = app.activeDocument;
app.selection = null;
app.paste();
var sel = app.selection[0];
var pt = sel.parentStory.contents;
var path = "~/Desktop/";
if(doc.saved == false) {
    doc.save(new File(path + pt + ".indd"));
 }

sel.remove();

 

 

TOPICS
Scripting

Views

45

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Javascript: Saving new file name as clipboard text

New Here ,
Aug 28, 2020

Copy link to clipboard

Copied

Hello. I currently work with quite a few InDesign template files (simply indesign files), which require me to relink pdf files to objects. I currently have a script that will save out the InDesign file to the specific location that needs to be saved to.

 

My current script looks like this:

var pt = app.paste();

if(app.activeDocument.saved == false) {
    app.activeDocument.save(new File("PATH" + pt + ".indd"));
 }

 

Thinking it through, I don't think the pasted text (app.paste) would work for the name, but I'm not sure if there's a way to grab the clipboard text, as I didn't see anything on the InDesign javascript scripting manual regarding this. Is something like this even possible/would there be any work arounds to being able to grab the text from the clipboard?

 

Thank you!

Adobe Community Professional
Correct answer by brianp311 | Adobe Community Professional

You need to paste it into something that you can then access. Calling paste on text makes a new textframe on your document and selects it. Thus, you can get it like this. I assume you have "PATH" defined somewhere else; in this case I saved to the Desktop. 

 

 

var doc = app.activeDocument;
app.selection = null;
app.paste();
var sel = app.selection[0];
var pt = sel.parentStory.contents;
var path = "~/Desktop/";
if(doc.saved == false) {
    doc.save(new File(path + pt + ".indd"));
 }

sel.remove();

 

 

TOPICS
Scripting

Views

46

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 28, 2020 0
Adobe Community Professional ,
Aug 28, 2020

Copy link to clipboard

Copied

You need to paste it into something that you can then access. Calling paste on text makes a new textframe on your document and selects it. Thus, you can get it like this. I assume you have "PATH" defined somewhere else; in this case I saved to the Desktop. 

 

 

var doc = app.activeDocument;
app.selection = null;
app.paste();
var sel = app.selection[0];
var pt = sel.parentStory.contents;
var path = "~/Desktop/";
if(doc.saved == false) {
    doc.save(new File(path + pt + ".indd"));
 }

sel.remove();

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 28, 2020 1
S_3_R_0 LATEST
New Here ,
Aug 28, 2020

Copy link to clipboard

Copied

This is exactly what I was looking for. Yes, I had a path already established and just had PATH as a substitute.


Thank you so much!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 28, 2020 0