Search code examples
variablesapplescriptadobe-illustrator

Illustrator Save Options and useing variable settings


Starting to work with Illustrator scripts and trying to write a script that would allow me to change a variable by input and effect the save settings. The save options I want to alter are as followed:

-- Save and overwrite
save theCurrentFile in file WorkPath as Illustrator ¬
  with options {class:Illustrator save options ¬
  , compatibility:Illustrator 14 ¬
  , embed linked files:true ¬
  , font subset threshold:0.0}

I want to be able to change the compatibility to a variable but no matter what I set the variable as, I can't get it to understand it. I am after something like this:

--Variable
set CompatibilityType to "Illustrator 14"

-- Save and overwrite
save theCurrentFile in file WorkPath as Illustrator ¬
  with options {class:Illustrator save options ¬
  , compatibility:CompatibilityType ¬
  , embed linked files:true ¬
  , font subset threshold:0.0}

What am I miss that this doesn't want to work. I have done similar things in a properties list.


Solution

  • Compatibility is represented as an enumeration defined in the Illustrator dictionary, not a string. You are trying to use "Illustrator 14" to represent the compatibility version. What you need is Illustrator 14. Notice the lack of quotes. You can use the following sub-routine to convert a string to an enumeration on the fly. Of course, you can change the string representations if you want. These are just the ones I use.

    set CompatibilityType to my convertIllustratorVersion("CS4")
    
    save theCurrentFile in file WorkPath as Illustrator ¬
      with options {class:Illustrator save options ¬
      , compatibility:CompatibilityType ¬
      , embed linked files:true ¬
      , font subset threshold:0.0}
    
    on convertIllustratorVersion(originalVersion)
        using terms from application "Adobe Illustrator"
            set versions to {"CS", "CS2", "CS3", "CS4", "CS5"}
            set enums to {Illustrator 11, Illustrator 12, Illustrator 13, Illustrator 14, Illustrator 15}
        end using terms from
    
        repeat with i from 1 to (count versions)
            if originalVersion is item i of versions then
                return item i of enums
            end if
        end repeat
    
        error (quoted form of originalVersion & " is not a valid Illustrator version")
    end convertVersionNumber