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

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

Explorer ,
Jan 02, 2024 Jan 02, 2024

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
3.1K
Translate
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

LEGEND , 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")

 

Translate
LEGEND , Jan 03, 2024 Jan 03, 2024

I think:

 

var pg = 3;

 

should work - or "3".

 

Translate
LEGEND ,
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")

 

Translate
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

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

Translate
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
LEGEND ,
Jan 03, 2024 Jan 03, 2024

I think:

 

var pg = 3;

 

should work - or "3".

 

Translate
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

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.

Translate
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
LEGEND ,
Jan 03, 2024 Jan 03, 2024

Great.

 

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

 

Translate
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

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

Translate
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
LEGEND ,
Jan 04, 2024 Jan 04, 2024

Thanks. 

 

If you need extra functionality - please let me know. 

 

Translate
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

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

Translate
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
LEGEND ,
Sep 10, 2024 Sep 10, 2024

What is the error? 

 

Translate
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

Nothing happens…

Translate
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
LEGEND ,
Sep 10, 2024 Sep 10, 2024

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

 

Translate
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

here it is for MAC OS in a txt file

Translate
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
LEGEND ,
Sep 10, 2024 Sep 10, 2024

Can you add: 

 

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

 

before Export JPEG comment ? 

 

Translate
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

 

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)

Translate
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
LEGEND ,
Sep 11, 2024 Sep 11, 2024

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?

 

Translate
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
LEGEND ,
Sep 11, 2024 Sep 11, 2024

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

 

Translate
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

OK thanks, I work on it !

Translate
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

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

Translate
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
LEGEND ,
Sep 11, 2024 Sep 11, 2024
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()? 

 

Translate
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

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

Translate
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
 
Translate
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
LEGEND ,
Sep 12, 2024 Sep 12, 2024

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.

 

Translate
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
LEGEND ,
Sep 12, 2024 Sep 12, 2024

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

 

Translate
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

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

Translate
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