Skip to main content
Inspiring
January 7, 2011
Question

Script to get names of placed images into text file for our database?

  • January 7, 2011
  • 2 replies
  • 9302 views

I know nothing about scripting in Illustrator, but am willing and interested to give it a try if this sounds doable.  All we want are the names--just a simple list of the names, such as

7009 LL.eps

Rsb shadow design.psd

3_Pt_STA_475_P3.tif

of placed images (in our Illustrator CS5 art) into text that we can either import (from a tab- or comma-delimited text file) or paste into our Filemaker database.

Right now everyone is RETYPING the names of all placed images into the database, with consequent mistakes, missed images, etc.  Then when we search our database to find which art uses a certain image...results are not to be trusted.

(If we could cut/paste from either the Links palette or Document Info, that'd be fine... but nope.  Not in Illustrator, although we were thrilled to see InDesign CS5 has "Copy Info For Selected Links", which is VERY helpful.)  In Illustrator, we can export Document Info to a text file, but artists seem to find that long document too unwieldy, and they revert to typing the names, especially if they only have a couple of placed images... and then we're back to error-laden data no matter how careful they try to be.  (Very right-brained folks, you understand.)

Is such a script even possible?  If so, where/how might I start?  We're on iMacs with the Adobe CS5 suite (and Filemaker 11, if that matters). Thanks.

This topic has been closed for replies.

2 replies

Participant
June 20, 2012

I am totally illiterate when it comes to scripts. Would either one of you be kind enough to share the actual script with me so I can use it on my projects. I tried to make one myself but I simply dont understand it at all.

quozAuthor
Inspiring
April 1, 2014

This ExtendScript Toolkit script gathers image names from the current Adobe Illustrator document and places them in a text file in a created /Users/Shared/Imagenames folder on the local hard drive.  My question is whether the script can still be distributed to multiple users when each user has a unique hard drive name.

After happily using this script for over 2 years, we upgraded to CS6 and Mavericks.  Formerly, "Macintosh HD" was the common hard drive name for all 7 of our iMac users. Now each hard drive is something like "amy1234".  (Our Mac sys admin, when "wiping" the hard drive and installing Mavericks and Adobe software, decided to go the unique route.)

I WAS able to fix the script so it works on MY system (e.g. "quoz4567").

Do I have to hard code the path in each user's copy of the script, or is there a more practical way around this?  (Our served Filemaker database, which imports the names, finds the file in Shared regardless of the user because it has a "get desktop path" command and I'm able to create a variable on the fly with the correct path per user.)

I wondered if such magic existed in ExtendScript Toolkit. I'm suspecting the Illustrator script would have to pass data to Applescript and have Applescript make the folder?  Or maybe this is all impossible!  I looked through "Illustrator-Scripting-Guide" but either it doesn't have that info or I (true, regardless) didn't comprehend what I saw...

I can certainly hardcode per Mac, just curious if the per user approach is doable.

The two parts of the script that reference the path are as follows:

var folderRef = new Folder("quoz4567 iMac/Users/Shared/IMAGENAMES");

folderRef.create();

... and further on near the end of the script...

function writeToFile(info) {

     try     {

          var log = File('quoz4567 iMac/Users/Shared/IMAGENAMES/ILL_ImageNames.txt');

          log.open('w');

          log.write(info + '\r');

          log.close()

... if more info is needed please let me know!  Thanks in advance.

CarlosCanto
Community Expert
Community Expert
April 2, 2014

(Our served Filemaker database, which imports the names, finds the file in Shared regardless of the user because it has a "get desktop path" command and I'm able to create a variable on the fly with the correct path per user.)

we can do this in javascript

var userDesktop = Folder.desktop;

alert(userDesktop);

Muppet_Mark-QAl63s
Inspiring
January 7, 2011

Yes this should be doable. Im only CS2 do you use multi-artboards? This should alert you of the first top level placed items name and full path.

// Just the name

alert(app.activeDocument.placedItems[0].file.name); // Full path to file alert(app.activeDocument.placedItems[0].file.fsName);

If this works for your items then looping and writing to text file should be OK…

quozAuthor
Inspiring
January 7, 2011

Great.  So my best way to get started, I assume, is check out the Scripting Documentation for Illustrator.  Any other tips or tidbits for an absolute newbie?  (I've done a bit Filemaker programming so I understand concepts like looping, etc., but know nothing of scripting.)

We don't use multiple artboards, though.  Just one design (package) per .ai document. 

Inspiring
January 7, 2011

placedItems does not report raster images (I didn't try EPSes). For raster images, you'd need "rasterItems".

This works, for a few placed bitmaps:

alert (app.activeDocument.rasterItems.length);

list = [];

for (i=0; i<app.activeDocument.rasterItems.length; i++)

     list.push (app.activeDocument.rasterItems.file.name);

f = app.activeDocument.textFrames.add();

f.contents = list.join("\r");

in that it creates a temporary text frame which gets filled with the image filenames. But getting the text to the clipboard is something else entirely -- I imagined it should be possible to

a. select the text in this temporary frame

b. copy it, using "app.copy()"

c. delete the temporary frame

d. .. and you can go to any other application to paste the list.

Unfortunately, it's not as straightforward as I thought. Simply asking Illy to "f.contents.select()" or "f.textRange.select()" or "f.textSelection = SELECT.ALL" or about anything logical gets rejected. Muppet Mark?