A script to place the most recent file from a folder
Here is a simple script that places the most recent file from a folder into the currently active Illustrator document. Every line is explained with a comment.
// the folder containing the files to place (change the path)
var folder = new Folder('D:/myFolder');
// an array of the files in the folder
var files = folder.getFiles();
// sort the files according to when they were last modified
files.sort(function(a, b) {
return a.modified.valueOf() < b.modified.valueOf() ? 1 : -1;
});
// small alert box to show which file is loaded, useful to debug
// alert(files[0]);
// the most recent file in the folder
var mostRecentFile = new File(files[0]);
// the active document
var document = app.activeDocument;
// a container for all placed items in the document
var placedItems = document.placedItems;
// add a new placed item
var newPlacedItem = placedItems.add();
// link the placed item to the most recent file
newPlacedItem.file = mostRecentFile;
As mentioned in one of the comments you of course need to specify the folder you want to use. The script is pretty raw. Tweaks and checks might be needed depending on your workflow. For example, the script will fail if the folder contains a newly created subfolder.
How to use the script
Copy the script text above and paste it into a text editor.
Save the script as a .jsx
file.
In Illustrator, use File > Scripts > Other Script, browse to the script file and press Open to run the script.
How to run the script with a function key
The only way I know to assign a function key to a script is a bit quirky. If someone knows a better way please edit.
The File > Scripts menu contains some featured scripts. In order to record an action executing a custom script, you need to add your script to that list. This is done by copying the script to the folder containing those featured scripts. On my computer they are in D:\Program Files\Adobe\Adobe Illustrator 2020\Presets\en_US\Scripts
.
Now you probably need to restart Illustrator before your script is added to the menu.
In the Actions panel, click Create New Action, assign a Function Key of your choice and click Record.
In the sandwich menu of the Actions panel, choose Insert Menu Item, search for the name of your script and click OK when you have located it.
In the Actions panel, click Stop Playing/Recording to end the recording.
Now you should be able to place the most recent file with one key press!