• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
9

Script to save a file in a specific folder with a specific name

Explorer ,
Jan 02, 2024 Jan 02, 2024

Copy link to clipboard

Copied

Hello,

I found a very useful script to save covers as JPEG, with a fixed width, whatever is the original size :

//the export pixel width
var targetWidthPixels = 600;

var doc = app.activeDocument;
with(doc.viewPreferences){
    horizontalMeasurementUnits = MeasurementUnits.INCHES;
    verticalMeasurementUnits = MeasurementUnits.INCHES;
}

//get the page width in inches
var pw=doc.documentPreferences.pageWidth;

//calulate the resolution needed to export the jpeg as 1500px wide
//if the page is 8.5" x 11", the output pixel dimensions will be 600px x 776px
var resout= targetWidthPixels/pw;

//the active page
var pg=app.activeWindow.activePage.name;

//set the res preference and page range
 with(app.jpegExportPreferences){
     exportResolution = resout;
     pageString = pg;
     antiAlias = true;
     embedColorProfile = true;
     jpegColorSpace = JpegColorSpaceEnum.RGB;
     //add other properties as needed
}
 
//export the JPEG
doc.exportFile(
		ExportFormat.jpg,
		File(Folder.desktop + "/ExportJPG.jpg"), 
		false
);

My question is : how to put this file in a specific folder (/Users/toto/Desktop/TEST MTP/OUT site) with a specific name wich is the 14 first characters of every Indesign file name (9782340-046337_COUV_2022_02_24.indd becomes 9782340-046337.jpg)

 

Thanks for your Help

TOPICS
Import and export , Scripting

Views

1.6K

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
community guidelines

correct answers 2 Correct answers

Community Expert , Jan 02, 2024 Jan 02, 2024

You have to modify this part:

 

File(Folder.desktop + "/ExportJPG.jpg") 

 

"Folder.desktop" would be your "/Users/toto/Desktop/TEST MTP/OUT site"

 

"/ExportJPG.jpg" would be something like that:

 

'/' + doc.name.substring(0,13) + '.jpg'

 

But I'm not JS guy so someone else needs to check and confirm.

 

File("/Users/toto/Desktop/TEST MTP/OUT site/" + doc.name.substring(0,13) + ".jpg")

 

Votes

Translate

Translate
Community Expert , Jan 03, 2024 Jan 03, 2024

I think:

 

var pg = 3;

 

should work - or "3".

 

Votes

Translate

Translate
Community Expert ,
Jan 02, 2024 Jan 02, 2024

Copy link to clipboard

Copied

You have to modify this part:

 

File(Folder.desktop + "/ExportJPG.jpg") 

 

"Folder.desktop" would be your "/Users/toto/Desktop/TEST MTP/OUT site"

 

"/ExportJPG.jpg" would be something like that:

 

'/' + doc.name.substring(0,13) + '.jpg'

 

But I'm not JS guy so someone else needs to check and confirm.

 

File("/Users/toto/Desktop/TEST MTP/OUT site/" + doc.name.substring(0,13) + ".jpg")

 

Votes

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
community guidelines
Explorer ,
Jan 03, 2024 Jan 03, 2024

Copy link to clipboard

Copied

Thanks a lot, it works fine.

Can you tell me how to select a specific page in the script.

Probably a change here?:

//the active page
var pg=app.activeWindow.activePage.name;

 The name of the page is "Print" and the number is 3

Votes

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
community guidelines
Community Expert ,
Jan 03, 2024 Jan 03, 2024

Copy link to clipboard

Copied

I think:

 

var pg = 3;

 

should work - or "3".

 

Votes

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
community guidelines
Explorer ,
Jan 03, 2024 Jan 03, 2024

Copy link to clipboard

Copied

Many thanks, it works perfectly! With this script and the app MadeToPrint, I can export in one click:

- 2 versions PDF of the cover with a different spine (with the alternative layout function in Indesign)

- 1 JPEG of the cover plate 1

- 1 JPEG of the cover plate 4

Each file in a different distant folder.

Votes

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
community guidelines
Community Expert ,
Jan 03, 2024 Jan 03, 2024

Copy link to clipboard

Copied

Great.

 

My ID-Tasker is much more versatile. The only slight limitation - can't be used directly on a Mac. 

 

Votes

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
community guidelines
Explorer ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

I didn't knew this tool but will quickly try it on a PC! Thanks.

Votes

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
community guidelines
Community Expert ,
Jan 04, 2024 Jan 04, 2024

Copy link to clipboard

Copied

Thanks. 

 

If you need extra functionality - please let me know. 

 

Votes

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
community guidelines
Explorer ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Hello,

Thanks again for your help in january!

The script works fine for MAC OS, but not for PC Windows 10 (I tried it yesterday). Do you have a clue?

Thanks

Votes

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
community guidelines
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

What is the error? 

 

Votes

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
community guidelines
Explorer ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Nothing happens…

Votes

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
community guidelines
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Can you show an example of the paths you are using? 

 

Votes

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
community guidelines
Explorer ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

here it is for MAC OS in a txt file

Votes

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
community guidelines
Community Expert ,
Sep 10, 2024 Sep 10, 2024

Copy link to clipboard

Copied

Can you add: 

 

alert("target" + doc.name.substring(0,13) + ".jpg");

 

before Export JPEG comment ? 

 

Votes

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
community guidelines
Explorer ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

 

LIke this?

/set the res preference and page range

 with(app.jpegExportPreferences){

     exportResolution = resout;

     pageString = pg;

     antiAlias = true;

     embedColorProfile = true;

     jpegColorSpace = JpegColorSpaceEnum.RGB;

     //add other properties as needed

}

alert("target" + doc.name.substring(0,13) + ".jpg") ;

//export the JPEG

doc.exportFile(

ExportFormat.jpg,

File("target" + doc.name.substring(0,13) + ".jpg"), 

false

);

It doesn't work.. (cf screen capture)

Votes

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
community guidelines
Community Expert ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

Yes. 

 

My alert shows wrong path - there is no "\" after "C:" and there is some wrong character after "MARKETING".

 

The error below - is about something else - 6th line, MeasurementUnits?

 

Votes

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
community guidelines
Community Expert ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

Looks like ALL "\" has been stripped from the path??

 

Votes

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
community guidelines
Explorer ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

OK thanks, I work on it !

Votes

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
community guidelines
Explorer ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

Yes sorry, it's because it is seen as wrong html and automaticaly corrected by the editor…

Votes

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
community guidelines
Community Expert ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

quote

Yes sorry, it's because it is seen as wrong html and automaticaly corrected by the editor…


By @Stephane27925305ylf8

 

Not sure what do you mean?

 

Alert() should display raw text - raw value of the doc.name.substring(0,13) - without any kind of "interpretation"? 

 

And you have "target" text at the beginning - it's not displayed in the alert()? 

 

Votes

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
community guidelines
Explorer ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

When I try to copy the script text, I have this message (capture)

Votes

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
community guidelines
Explorer ,
Sep 11, 2024 Sep 11, 2024

Copy link to clipboard

Copied

 

Votes

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
community guidelines
Community Expert ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

I was refering to this screenshot:

 

RobertatIDTasker_0-1726135855209.png

 

Top - "my" alert message - missing ALL "\". So the final path to the file is wrong.

 

Bottom - you have an error in line 6.

 

You should use:

RobertatIDTasker_1-1726135976072.png

to post code here.

 

Votes

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
community guidelines
Community Expert ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

OK, it looks like the error is about "modal dialog" being open?

 

Votes

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
community guidelines
Explorer ,
Sep 12, 2024 Sep 12, 2024

Copy link to clipboard

Copied

No, it's just that the script does not launch when I play it on the PC. Just Nothing…

Votes

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
community guidelines