Skip to main content
Known Participant
March 28, 2022
Answered

Save an illustrator file name containing the date and names of the links

  • March 28, 2022
  • 2 replies
  • 1378 views

 

 

Hi

I'm looking for a script that every time I run it, it will write to me when saving the file the current date (no = .         _  = yes), and with spaces the names of the links that exist in the document.

This topic has been closed for replies.
Correct answer Disposition_Dev
//Author: Dilliam Wowling
//email: illustrator.dev.pro@gmail.com
//github: github.com/wdjsdev/public_illustrator_scripts
//Adobe Forum Post: https://community.adobe.com/t5/illustrator-discussions/save-an-illustrator-file-name-containing-the-date-and-names-of-the-links/td-p/12842255
//Language: javascript/extendscript
//Script Name: Save Doc With Date And Link Names
//deSCRIPTion: Saves the current document with a date and the names of the links in the document.


//Was this helpful? 
//Did it save you time and money?
//Would you like to say thanks by buying me a cup of
//coffee or a new car or anything in between?
//https://www.paypal.me/illustratordev


#target Illustrator
function SaveDocWithDateAndLinkNames()
{
	const doc = app.activeDocument;

	//get the current date formatted like this: dd-mm-yyyy
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1; //January is 0!
	var yyyy = today.getFullYear();

	var curDate = dd+'_'+mm+'_'+yyyy;

	//get the links in the current document
	var links = doc.placedItems;
	var linkNames = [];

	for(var i = 0; i < links.length; i++)
	{
		linkNames.push(decodeURI(links[i].file.name).replace(/\.[^\.]*$/, ""));
	}

	var newFileName = curDate + " " + linkNames.join(" ") + ".ai";
	var outputFolderPath;
	if(!doc.saved || doc.name.match(/untitled/i) || !doc.path)
	{
		outputFolderPath = decodeURI(Folder.selectDialog("Select the folder to save the file to").fullName);
	}
	else
	{
		outputFolderPath = decodeURI(doc.path);
	}

	if(!outputFolderPath)
	{
		alert("No folder selected.\nOperation cancelled.");
		return;
	}

	doc.saveAs(File(outputFolderPath + "/" + newFileName));

    for(var i = 0; i < links.length; i++)
    {
        links[i].embed();
    }

    doc.save();

}
SaveDocWithDateAndLinkNames();

2 replies

Disposition_Dev
Legend
March 29, 2022

Give this a try:

https://github.com/wdjsdev/public_illustrator_scripts/blob/master/save_doc_with_date_and_link_names.js

 

//Author: Dilliam Wowling
//email: illustrator.dev.pro@gmail.com
//github: github.com/wdjsdev/public_illustrator_scripts
//Adobe Forum Post: https://community.adobe.com/t5/illustrator-discussions/save-an-illustrator-file-name-containing-the-date-and-names-of-the-links/td-p/12842255
//Language: javascript/extendscript
//Script Name: Save Doc With Date And Link Names
//deSCRIPTion: Saves the current document with a date and the names of the links in the document.


//Was this helpful? 
//Did it save you time and money?
//Would you like to say thanks by buying me a cup of
//coffee or a new car or anything in between?
//https://www.paypal.me/illustratordev


#target Illustrator
function SaveDocWithDateAndLinkNames()
{
	const doc = app.activeDocument;

	//get the current date formatted like this: dd-mm-yyyy
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1; //January is 0!
	var yyyy = today.getFullYear();

	var curDate = dd+'_'+mm+'_'+yyyy;

	//get the links in the current document
	var links = doc.placedItems;
	var linkNames = [];

	for(var i = 0; i < links.length; i++)
	{
		linkNames.push(decodeURI(links[i].file.name).replace(/\.[^\.]*$/, ""));
	}

	var newFileName = curDate + " " + linkNames.join(" ") + ".ai";
	var outputFolderPath;
	if(!doc.saved || doc.name.match(/untitled/i) || !doc.path)
	{
		outputFolderPath = decodeURI(Folder.selectDialog("Select the folder to save the file to").fullName);
	}
	else
	{
		outputFolderPath = decodeURI(doc.path);
	}

	if(!outputFolderPath)
	{
		alert("No folder selected.\nOperation cancelled.");
		return;
	}

	doc.saveAs(File(outputFolderPath + "/" + newFileName));

}
SaveDocWithDateAndLinkNames();
aviel222Author
Known Participant
March 29, 2022

Thank you!
Can you put in command code that will embed the links
After saving, then again automatically save the file?

Disposition_Dev
Disposition_DevCorrect answer
Legend
March 29, 2022
//Author: Dilliam Wowling
//email: illustrator.dev.pro@gmail.com
//github: github.com/wdjsdev/public_illustrator_scripts
//Adobe Forum Post: https://community.adobe.com/t5/illustrator-discussions/save-an-illustrator-file-name-containing-the-date-and-names-of-the-links/td-p/12842255
//Language: javascript/extendscript
//Script Name: Save Doc With Date And Link Names
//deSCRIPTion: Saves the current document with a date and the names of the links in the document.


//Was this helpful? 
//Did it save you time and money?
//Would you like to say thanks by buying me a cup of
//coffee or a new car or anything in between?
//https://www.paypal.me/illustratordev


#target Illustrator
function SaveDocWithDateAndLinkNames()
{
	const doc = app.activeDocument;

	//get the current date formatted like this: dd-mm-yyyy
	var today = new Date();
	var dd = today.getDate();
	var mm = today.getMonth()+1; //January is 0!
	var yyyy = today.getFullYear();

	var curDate = dd+'_'+mm+'_'+yyyy;

	//get the links in the current document
	var links = doc.placedItems;
	var linkNames = [];

	for(var i = 0; i < links.length; i++)
	{
		linkNames.push(decodeURI(links[i].file.name).replace(/\.[^\.]*$/, ""));
	}

	var newFileName = curDate + " " + linkNames.join(" ") + ".ai";
	var outputFolderPath;
	if(!doc.saved || doc.name.match(/untitled/i) || !doc.path)
	{
		outputFolderPath = decodeURI(Folder.selectDialog("Select the folder to save the file to").fullName);
	}
	else
	{
		outputFolderPath = decodeURI(doc.path);
	}

	if(!outputFolderPath)
	{
		alert("No folder selected.\nOperation cancelled.");
		return;
	}

	doc.saveAs(File(outputFolderPath + "/" + newFileName));

    for(var i = 0; i < links.length; i++)
    {
        links[i].embed();
    }

    doc.save();

}
SaveDocWithDateAndLinkNames();
m1b
Community Expert
Community Expert
March 28, 2022

Hi @aviel222, I reckon it would help if you gave us a few examples of filenames.

- Mark

Participating Frequently
March 29, 2022

there is example:

 

29_3_22 345432 34343 4987654

 

the 345432 34343 4987654 are the names of the links.

 

aviel

 

Participating Frequently
March 29, 2022

another example:

 

3_3_22   cc.pdf   ee.pdf

important to remove the periods from the file name = 3_3_22  cc ee

 

aviel (from my work place)