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

How to create an action/script for saving multiple times different versions of the same file

New Here ,
Oct 21, 2010 Oct 21, 2010

I have an issue that I have been trying to fix for a while now and am needing some support. I continuously have to save .ai files in 4 different types for every art file I complete for customers. I am really wanting to streamline this a bit and was wanting to know if someone coule either point me in the right direction or maybe have the code already to do so. Here is what it boils down to:

Save file (as is; in its current directory)

Save file as (Save PDF; Same Name; Same Directory)

CMD+A; CMD-Shift-O (outline everything)

Save file as (Save .ai; Append name with "_OL_; Same DIrectory)

Save file as (Save .ai CS2 Format {for customers without CS3 and up}; Append previous save with "CS2"; Same DIrectory)

Close file

The issue I am having currently in creating actions is that each time I create the "Save file as" it always uses the name that was typed in during the action being made and always saves it to that (incorrect) location.

Any help would be greatly appreciated!

Thanks,

Brett

TOPICS
Scripting
3.7K
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 1 Correct answer

Guide , Oct 21, 2010 Oct 21, 2010

Brett, the code you have posted is AppleScript and contains quite a bit of stuff that you don't require… Can you give this a try it's Adobe's ExtendScript. I think it should do what you asked for (does for me with a quick test file). If your unsure what to do with this then post back…

#target illustrator function saveVersions()      {      if (app.documents.length == 0) return;           var docRef = app.activeDocument;      docRef.save();            var docName = docRef.name;      var nameStr

...
Translate
Adobe
Guide ,
Oct 21, 2010 Oct 21, 2010

Script would either need to know all of your pdf options to create a save options object with the correct properties or better still you use a pdf preset and the script can use get by name. You only need create outlines of your text frames I presume…?

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
New Here ,
Oct 21, 2010 Oct 21, 2010

Correct. I have merged the two scripts provided by Adobe "CollectforOutput" and "SaveArtboardasPDF" to make it save as PDFs (although it is opening the PDF everytime I use it); I am sure there is a way to tell it not to do this or like you said to tell it to use a specific preset. Yes only of the text frames. I usually do this as a CMD-A CMD-Shift-O to just grab everything and convert it. this is what I have so far in the script:

********

tell application "Adobe Illustrator"
    set numDocs to count of documents
    if numDocs > 0 then
        if button returned of (display dialog "Collect the current Illustator document for output?") is "OK" then
            tell me to collectCurrentDoc()
        end if
    else
        tell application "Finder" to set sampleFile to choose file with prompt "Locate the file 'Sample.ai'"
        open sampleFile
        tell me to collectCurrentDoc()
    end if
end tell

on openAndCollect(myfile)
    try
        tell application "Adobe Illustrator" to open myfile with options {update legacy text:true}
        collectCurrentDoc()
        tell application "Adobe Illustrator" to close document 1 saving no
    on error myerr
        display dialog myerr
    end try
end openAndCollect

on collectCurrentDoc()
    tell application "Finder"
        activate
        set myFolder to (choose folder with prompt "Folder to save collected files") as string
    end tell
    try
        tell application "Adobe Illustrator"
            set docRef to document 1
            set mydocname to name of docRef
            save docRef in file (myFolder & mydocname)
            set pdfSaveOptions to {class:PDF save options, view pdf:true}
            save docRef in file (myFolder & mydocname) as pdf with options pdfSaveOptions
            set myrasters to every raster item of docRef whose embedded is false
            set myplaceds to every placed item of docRef
            set mytextarts to every text frame of docRef
            set theFilepath to file path of docRef
        end tell
        collectArtToLocal(myrasters, theFilepath)
        collectArtToLocal(myplaceds, theFilepath)
    on error myerr
        display dialog myerr
    end try
end collectCurrentDoc

on collectArtToLocal(myItems, theFilepath)
    tell application "Finder" to set myillfilecontainer to container of theFilepath
    repeat with myItem in myItems
        tell application "Adobe Illustrator" to set myfile to (file path of myItem)
        tell application "Finder"
            set myfilecontainer to (container of myfile)
            set myFileName to (name of myfile)
            if myfilecontainer ≠ myillfilecontainer then
                if not ((file myFileName of myillfilecontainer) exists) then
                    set mynewfile to (duplicate myfile to myillfilecontainer)
                end if
            end if
        end tell
    end repeat
end collectArtToLocal

********

I am trying to adjust this part:

tell application "Adobe Illustrator"
             set docRef to document 1
             set mydocname to name of docRef
             save docRef in file (myFolder & mydocname)
             set pdfSaveOptions to {class:PDF save options, view pdf:true}
             save docRef in file (myFolder & mydocname) as pdf with options pdfSaveOptions
             set myrasters to every raster item of docRef whose embedded is false
             set myplaceds to every placed item of docRef
             set mytextarts to every text frame of docRef
             set theFilepath to file path of docRef
         end tell

to tell it to save docRef in file(myFolder & mydocname)...... but to append my OL and OLCS2 (also making sure it is saving as ai and a CS2 version of ai; after of course applying the Outline change. I am dredging through it but am not sure where to look to find the code that would provide what I am looking for.

Brett

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
Guide ,
Oct 21, 2010 Oct 21, 2010

Brett, the code you have posted is AppleScript and contains quite a bit of stuff that you don't require… Can you give this a try it's Adobe's ExtendScript. I think it should do what you asked for (does for me with a quick test file). If your unsure what to do with this then post back…

#target illustrator function saveVersions()      {      if (app.documents.length == 0) return;           var docRef = app.activeDocument;      docRef.save();            var docName = docRef.name;      var nameString = '';      var extOffset = docName.lastIndexOf('.');      if (extOffset == -1) {           nameString = docName;      } else {           nameString = docName.substr(0, extOffset);      }      var docPath = docRef.path.fsName;            var pdfOptions = new PDFSaveOptions();      pdfOptions.pDFPreset = '[Press Quality]';            var saveFile = new File(docPath+'/'+nameString+'.pdf');        docRef.saveAs(saveFile, pdfOptions);            var docText = docRef.textFrames;      for (var i = docText.length-1; i >= 0; i--)           {           docText.createOutline();           }            var aiOptions = new IllustratorSaveOptions();      aiOptions.compatibility = Compatibility.ILLUSTRATOR13; // CS3      aiOptions.compressed = true;      aiOptions.embedICCProfile = true;      aiOptions.embedLinkedFiles = true;      aiOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;      aiOptions.fontSubsetThreshold = 0;      aiOptions.overprint = PDFOverprint.PRESERVEPDFOVERPRINT;      aiOptions.pdfCompatible = true      var saveFile = new File(docPath+'/'+nameString+'_OL.ai');      docRef.saveAs(saveFile, aiOptions);            aiOptions.compatibility = Compatibility.ILLUSTRATOR12; // CS2            var saveFile = new File(docPath+'/'+nameString+'_OL_CS2.ai');        docRef.saveAs(saveFile, aiOptions);            docRef.close();      }      saveVersions();

It's expecting you to have a document open in Illustrator or it will do 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
New Here ,
Oct 21, 2010 Oct 21, 2010

This is what I ended up with and it works perfectly for exactly what I wanted:

(**********************************************************

ADOBE SYSTEMS INCORPORATED
Copyright 2005-2008 Adobe Systems Incorporated
All Rights Reserved

NOTICE:  Adobe permits you to use, modify, and
distribute this file in accordance with the terms
of the Adobe license agreement accompanying it. 
If you have received this file from a source
other than Adobe, then your use, modification,
or distribution of it requires the prior
written permission of Adobe.

*********************************************************)

tell application "Adobe Illustrator"
    set numDocs to count of documents
    if numDocs > 0 then
        if button returned of (display dialog "Collect the current Illustator document for output?") is "OK" then
            tell me to collectCurrentDoc()
        end if
    else
        tell application "Finder" to set sampleFile to choose file with prompt "Locate the file 'Sample.ai'"
        open sampleFile
        tell me to collectCurrentDoc()
    end if
end tell

on openAndCollect(myfile)
    try
        tell application "Adobe Illustrator" to open myfile with options {update legacy text:true}
        collectCurrentDoc()
        tell application "Adobe Illustrator" to close document 1 saving no
    on error myerr
        display dialog myerr
    end try
end openAndCollect

on collectCurrentDoc()
    tell application "Finder"
        activate
        set myFolder to (choose folder with prompt "Folder to save collected files") as string
    end tell
    try
        tell application "Adobe Illustrator"
            set docRef to document 1
            set mydocname to name of docRef
            save docRef in file (myFolder & mydocname)
            set pdfSaveOptions to {class:PDF save options, view pdf:false}
            save docRef in file (myFolder & mydocname) as pdf with options pdfSaveOptions
            convert to paths (every text frame of docRef)
            save docRef in file (myFolder & mydocname & "OL.ai") as Illustrator
            save docRef in file (myFolder & mydocname & "OL_CS2.ai") as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 12, embed linked files:true, font subset threshold:0.0}
            set myrasters to every raster item of docRef whose embedded is false
            set myplaceds to every placed item of docRef
            set mytextarts to every text frame of docRef
            set theFilepath to file path of docRef
        end tell
        collectArtToLocal(myrasters, theFilepath)
        collectArtToLocal(myplaceds, theFilepath)
    on error myerr
        display dialog myerr
    end try
end collectCurrentDoc

on collectArtToLocal(myItems, theFilepath)
    tell application "Finder" to set myillfilecontainer to container of theFilepath
    repeat with myItem in myItems
        tell application "Adobe Illustrator" to set myfile to (file path of myItem)
        tell application "Finder"
            set myfilecontainer to (container of myfile)
            set myFileName to (name of myfile)
            if myfilecontainer ≠ myillfilecontainer then
                if not ((file myFileName of myillfilecontainer) exists) then
                    set mynewfile to (duplicate myfile to myillfilecontainer)
                end if
            end if
        end tell
    end repeat
end collectArtToLocal

I just combined some adobe stuff with some stuff I saw in other threads until I understood what was expected.

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
Participant ,
Oct 22, 2010 Oct 22, 2010

Hi Mark,

Thanks for your script. I am also looking for same kind of script. But with small changes. Here are the details....

I  do have lot of AI files (from different paths) which are completly work done. So I just need to make them (all files) a copy with all text curves in the same path should create folder name called 'LC'.

  • From the given path all the files should save as to 'LC' folder. ('LC' folder needs to create at the same location and original file should stay as it was, so no changes in original/source file)
  • While making curves we must remember that layers contains lock. So have to unlock all the layer and make curves and lock them back.
  • While save as the all files in the file names should add '_LC' at last. For example: file name is 'xyzxyz.ai'. It should come 'xyzxyz_LC.ai'

FYI: Using Adobe CS4...

if you help me that would be really greatfule...

thanks in advance..

Kind Regards

HARI

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
New Here ,
Oct 22, 2010 Oct 22, 2010

Hari_kdr

I am interested in this too. I just realized that my _OL_CS2.ai file (OUtlined in Illustrator CS2 format), has been embedding linked files... which would be really bad. That was an easy fix, but now I noticed my file naming is off. I didn't notice this when I was originally building it but now i have noticed tha the files en xxxx.ai_OL.ai; causing .ai to show up twice. Ugh, so frustrating. Also I would love to make it uncheck all layers before converting to paths; otherwise it causes an error.

Brett

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
New Here ,
Oct 22, 2010 Oct 22, 2010

Ok I got this part for making visible and unlockinglayers of your document before outlining:

I inserted;

set visible of (layers of docRef) to true
set locked of (layers of docRef) to false
convert to paths (every text frame of docRef)

Here is my full script so far.... still needing to fix the nomenclature;


tell application "Adobe Illustrator"
    set numDocs to count of documents
    if numDocs > 0 then
        if button returned of (display dialog "Collect the current Illustator document for output?") is "OK" then
            tell me to collectCurrentDoc()
        end if
    else
        tell application "Finder" to set sampleFile to choose file with prompt "Locate the file 'Sample.ai'"
        open sampleFile
        tell me to collectCurrentDoc()
    end if
end tell

on openAndCollect(myfile)
    try
        tell application "Adobe Illustrator" to open myfile with options {update legacy text:true}
        collectCurrentDoc()
        tell application "Adobe Illustrator" to close document 1 saving no
    on error myerr
        display dialog myerr
    end try
end openAndCollect

on collectCurrentDoc()
    tell application "Finder"
        activate
        set myFolder to (choose folder with prompt "Folder to save collected files") as string
    end tell
    try
        tell application "Adobe Illustrator"
            set docRef to document 1
            set mydocname to name of docRef
            save docRef in file (myFolder & mydocname)
            set pdfSaveOptions to {class:PDF save options, view pdf:false}
            save docRef in file (myFolder & mydocname) as pdf with options pdfSaveOptions
            set visible of (layers of docRef) to true
            set locked of (layers of docRef) to false
            convert to paths (every text frame of docRef)
            save docRef in file (myFolder & mydocname & "_OL.ai") as Illustrator
            save docRef in file (myFolder & mydocname & "_OL_CS2.ai") as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 12, embed linked files:false, font subset threshold:0.0}
            set myrasters to every raster item of docRef whose embedded is false
            set myplaceds to every placed item of docRef
            set mytextarts to every text frame of docRef
            set theFilepath to file path of docRef
        end tell
        collectArtToLocal(myrasters, theFilepath)
        collectArtToLocal(myplaceds, theFilepath)
    on error myerr
        display dialog myerr
    end try
end collectCurrentDoc

on collectArtToLocal(myItems, theFilepath)
    tell application "Finder" to set myillfilecontainer to container of theFilepath
    repeat with myItem in myItems
        tell application "Adobe Illustrator" to set myfile to (file path of myItem)
        tell application "Finder"
            set myfilecontainer to (container of myfile)
            set myFileName to (name of myfile)
            if myfilecontainer ≠ myillfilecontainer then
                if not ((file myFileName of myillfilecontainer) exists) then
                    set mynewfile to (duplicate myfile to myillfilecontainer)
                end if
            end if
        end tell
    end repeat
end collectArtToLocal

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
New Here ,
Oct 22, 2010 Oct 22, 2010

Ok, I have looked on and on and am now stuck.

I am trying to get two more things accomplished with my script and can't seem to find the information I need.. I have tried though...

I want the files from my script to be placed in the "Current Opened and Active Document of Illustrator" residing folder

Also, my script is naming things incorrectly and I can't seem to get them to stop

for instance I want:

20626_2.ai

to resave through script as

20626_2_OL.ai

I am getting

20626_2.ai_OL.ai

Please help if someone can find my errors: Code Posted:

tell application "Adobe Illustrator"
    set numDocs to count of documents
    if numDocs > 0 then
        tell me to collectCurrentDoc()
    else
        tell application "Finder" to set sampleFile to choose file with prompt "Locate the file 'Sample.ai'"
        open sampleFile
        tell me to collectCurrentDoc()
    end if
    close document 1 saving no
end tell

on openAndCollect(myfile)
    try
        tell application "Adobe Illustrator" to open myfile with options {update legacy text:true}
        collectCurrentDoc()
        tell application "Adobe Illustrator" to close document 1 saving no
    on error myerr
        display dialog myerr
    end try
end openAndCollect

on collectCurrentDoc()
    tell application "Finder"
        activate
        set myFolder to (choose folder with prompt "Folder to save collected files") as string
    end tell
    try
        tell application "Adobe Illustrator"
            set docRef to document 1
            set mydocname to name of docRef
            save docRef in file (myFolder & mydocname)
            set pdfSaveOptions to {class:PDF save options, view pdf:false}
            save docRef in file (myFolder & mydocname) as pdf with options pdfSaveOptions
            set visible of (layers of docRef) to true
            set locked of (layers of docRef) to false
            convert to paths (every text frame of docRef)
            save docRef in file (myFolder & mydocname & "_OL.ai") as Illustrator
            save docRef in file (myFolder & mydocname & "_OL_CS2.ai") as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 12, embed linked files:false, font subset threshold:0.0}
            set myrasters to every raster item of docRef whose embedded is false
            set myplaceds to every placed item of docRef
            set mytextarts to every text frame of docRef
            set theFilepath to file path of docRef
        end tell
        collectArtToLocal(myrasters, theFilepath)
        collectArtToLocal(myplaceds, theFilepath)
    on error myerr
        display dialog myerr
    end try
end collectCurrentDoc

on collectArtToLocal(myItems, theFilepath)
    tell application "Finder" to set myillfilecontainer to container of theFilepath
    repeat with myItem in myItems
        tell application "Adobe Illustrator" to set myfile to (file path of myItem)
        tell application "Finder"
            set myfilecontainer to (container of myfile)
            set myFileName to (name of myfile)
            if myfilecontainer ≠ myillfilecontainer then
                if not ((file myFileName of myillfilecontainer) exists) then
                    set mynewfile to (duplicate myfile to myillfilecontainer)
                end if
            end if
        end tell
    end repeat
end collectArtToLocal

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
Community Expert ,
Oct 22, 2010 Oct 22, 2010

Here's a SaveAsEPS script which should provide some leads.

---------------------------------

tell application "Adobe Illustrator"
    try
        set origPath to file path of current document as text
        set currentName to name of current document
        set nameLength to (count currentName) + 1
        set saveLocation to text 1 thru -nameLength of origPath
    on error
        set saveLocation to (choose folder with prompt "Select location to save file:")
        set currentName to name of current document
    end try
   
    set nameInput to (display dialog "Please enter new file name:" default answer currentName)
    set newName to text returned of nameInput
   
    if text -1 thru -4 of newName = ".eps" then
        set newFile to saveLocation & newName as text
    else if newName does not contain ".eps" then
        set newFile to saveLocation & newName & ".eps" as text
    end if
   
    if origPath = newFile then
        display dialog "A file with this name already exists. Do you want to replace it with this new file?"
    end if
   
    save current document in file newFile as eps with options {class:EPS save options, preview:color Macintosh, overprint:discard, embed all fonts:true, embed linked files:false, include document thumbnails:true, compatible gradient printing:true, CMYK PostScript:false, PostScript:level 2}
end tell

--------------------------------------

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
New Here ,
Oct 22, 2010 Oct 22, 2010

Larry,

I have been trying to figure out what would be helpful and have tried using some of the code in there and understand it but I haven't seen what in there would allow me to get rid of the superfluous .ai

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
Community Expert ,
Oct 22, 2010 Oct 22, 2010

You are using in your script set name of the file to the name of docRef. This includes the .ai. You need to remove this before you add the new _OL.ai or whatever it it that you are adding. Here's another bit that you might be able to incorporate

set mydocname to displayed name of docRef -- get displayed name

set AppleScript's text item delimiters to "."

set newDocName to text item 1 of mydocname

Put this in place of your line

set mydocname to name of docRef

and change the variable in this line

save docRef in file (myFolder & mydocname)

to newDocName and do the same to the other similar lines

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
New Here ,
Oct 22, 2010 Oct 22, 2010

You are awesome! Everything works now.

Can I ask, since I am trying to learn this, did the line

set AppleScript's text item delimiters to "."


pretty much just "erase" the name &

set newDocName to text item 1 of mydocname

replaced the name with just the text before the extension and set it as newDocName?

Trying to figure out what it was that just happened

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
Community Expert ,
Oct 22, 2010 Oct 22, 2010

The text delimiter is used to indicate parts of the name to the script. After saying this, text 1 of the doc name is XXXXXX and text 2 is ai so that you can address each part seperately. Basically you have the idea.

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
Guide ,
Oct 22, 2010 Oct 22, 2010

set AppleScript's text item delimiters to "."

Sets the character(s) that you wish to use to split a string into smaller chunks of text. The result from your file name should be 2 text items if your file had an extension and no other full stops anywhere in the name. Each text item would be what was either side and not include your delimiter. You should look these up in the Apple reference as they should also be put back after being used other wise it could lead to unwanted string operations later in your script.

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
New Here ,
Oct 22, 2010 Oct 22, 2010
LATEST

Very interesting. I see where any extra stops in the name causes an issue but that should keep proper naming for files in check around here.

I will look them up in the Apple reference I really appreciate the help guys!

Thanks!

Brett

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