saving images in a specific folder

New Here ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

Hi à la ligne

I use a script to convert all images to jpg format. This part of the script is OK.

 

var myDoc = app.activeDocument,
apis = myDoc.allPageItems, rect, fileName;

while ( rect = apis.pop() )
{
alert(rect.graphics[0].itemLink.filePath)
if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue; }

fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );

app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;

//make new folder
var f = new Folder("C:/Users/laure/Creative Cloud Files/SousLeSoleil_Livre/Links/Images/");
f.create();

//give it a unique name
var myFile = new File('C:/Users/laure/Creative Cloud Files/SousLeSoleil_Livre/Links/Images/' + fileName);

rect.exportFile(ExportFormat.JPG, myFile);

 

I have to specify the file path manualy (bold). 

I would like to save the jpg images in the a new folder (ex.: /images/) in the /Links/ folder anywhere the Package is save.

Is it possible to change this script to do this ?

Thanks for help.

Best

LT

TOPICS
Scripting

Views

80

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

correct answers 2 Correct answers

Advocate , Dec 15, 2021 Dec 15, 2021
Hello @laurent tourniel7664515, Give this a try...var myDoc = app.activeDocument, apis = myDoc.allPageItems, rect, fileName; while ( rect = apis.pop() ) { // alert(rect.graphics[0].itemLink.filePath) if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue; } fileName = File ( rect.graphics[0].itemLink.filePath ).name; fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' ); app.jpegExportPreferences.exportResolution = 300; app.jpegExportPreferences.jpegQuality = JPEGOptions...

Likes

Translate

Translate
Adobe Community Professional , Dec 15, 2021 Dec 15, 2021
Hi LT, The path to a packaged InDesign file’s Links folder would be: var linkFolder = app.activeDocument.filePath + "/Links" //add an Images folder var f = new Folder(linkFolder + "/Images/"); f.create();

Likes

Translate

Translate
Advocate ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

Hello @laurent tourniel7664515,

 

Give this a try...

var myDoc = app.activeDocument,
apis = myDoc.allPageItems, rect, fileName;

while ( rect = apis.pop() )
{
// alert(rect.graphics[0].itemLink.filePath)
if ( !(rect instanceof Rectangle) || !rect.graphics[0].isValid ){ continue; }

fileName = File ( rect.graphics[0].itemLink.filePath ).name;
fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );

app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MEDIUM;

//make new folder
var f = new Folder(myDoc.filePath + "/Links/Images/");
f.create();

//give it a unique name
var myFile = new File(f +'/' + fileName);

rect.exportFile(ExportFormat.JPG, myFile);
}

Regards,

Mike

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
community guidelines
New Here ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

Thanks a lot, Mike.

It is perfect.

Best

Laurent

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
community guidelines
Adobe Community Professional ,
Dec 15, 2021 Dec 15, 2021

Copy link to clipboard

Copied

LATEST

Hi LT, The path to a packaged InDesign file’s Links folder would be:

 

var linkFolder = app.activeDocument.filePath + "/Links"

//add an Images folder
var f = new Folder(linkFolder + "/Images/");
f.create();

 

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