Setting up Illustrator options in a script

I’m having difficulty with the ‘class: save pdf options’ in a small Applescript for use in Illustrator 10.

I need to be able to set the different save options as variables eg. currently {compatibility:Acrobat 5}, but would like to use {compatibility:acrobatVersion} where the variable acrobatVersion is defined earlier in the script.

The problem is Illustrator doesn’t like it when I use a variable for this, and returns an error message, “Can’t make some data into the expected type”. Does anyone know how to solve this problem?

Note: I’m not having problems with all the preferences, only the ones such as ‘compatibility’ and ‘color compression’ which seem to require a text string. I can correctly set any numerical or boolean options eg. ‘color downsampling’.

(* This script resaves any open Illustrator 10 files as pdf files to a folder the user specifies *)

set targetFolder to choose folder with prompt "Location for exported files"
tell application "Finder" to set targetPath to item targetFolder as string

tell application "Adobe Illustrator 10"
	set user interaction level to never interact
	set documentCount to count documents
	-- I don't think I'm setting the following variables correctly for AcrobatVersion and ColourCompression. The SubsetFonts variable is working though.
	set AcrobatVersion to "Acrobat 5" --can be set as either Acrobat 4 or Acrobat 5
	set SubsetFonts to "100" as real --can be a number from 0 - 100
	repeat with i from 1 to documentCount
		set documentName to name of document i
		(*Perform the save
		Currently, the script will fail at this point. Illustrator returns the message, "Adobe Illustrator 10 got an error: Can't make some data into the expected type." 
		The problem is the AcrobatVersion variable. It is not set as the correct type of data for Illustrator. But, I don't know what it should be!*)
		save document i in file (targetPath & documentName) as pdf �
			with options {class:PDF save options, compatibility:AcrobatVersion, preserve editability:true, embed all fonts:true, font subset threshold:SubsetFonts, generate thumbnails:true, color downsampling:150, color compression:JPEG high, grayscale downsampling:150, grayscale compression:JPEG high, monochrome downsampling:1200, monochrome compression:ZIP, compress art:true}
	end repeat
end tell


Try doing a search on this site for “pdf” (I did, and came up with quite a few threads). Also check out this link:

It’s for OS/9, I believe, but you could probably adapt it to suit your purpose.

I hope this helps.


Variable as the shade

I had already searched and wasn’t able to find what I required.

I’m not after a script to export to pdf from Illustrator per say. I’m building a more complex program in Applescript Studio where I need to find out how to set variables for the ‘class: save pdf options’. I would run into the same problem if I was saving to .eps or exporting to Photoshop.

I just don’t know how to set the variable type correctly.

I have been trying to get help writing a very simple applescript for illustrator CS. i started with an AI 10 script and am trying to adapt it. One of the things you are looking for is included in the script that was given to me.
here is the script I started with:


set fileTypes to {"EPSF", "PDF ", "ART5"} -- file types available to resave as Illustrator

-- get a sourceFolder that holds the files to resave as AI
set sourceFolder to (choose folder with prompt "Choose a folder with files to resave as Illustrator:") as text

-- get a list of files of the defined type in the sourceFolder
tell application "Finder" to set workingFiles to (every file of folder sourceFolder whose file type is in fileTypes) as alias list
-- now you have your fileList argument

-- get a destinationFolder to hold the PDFs
set destinationFolder to (choose folder with prompt "Choose a folder to hold the Illustrator files:") as text

SaveFilesAsAI10(workingFiles, destinationFolder)

on SaveFilesAsAI10(fileList, destinationFolder)
	set destinationPath to destinationFolder as string
	repeat with aFile in fileList
		tell application "Finder" to set fileName to (name of aFile)
		set newFilePath to destinationPath & fileName
		tell application "Illustrator CS"
			open aFile
			save current document in file newFilePath as Illustrator with options {class:Illustrator save options, embed linked files:true, PDF compatible:true, font subset threshold:0.0}
			close current document saving no
		end tell
	end repeat
end SaveFilesAsAI10


i also posted more parts of such code elsewhere…
take a look at what i posted here:

I hope the snippet of code i posted helps you and maybe if you have a few minutes you can help me.