Bypassing dialog in Illustrator actions

Hey all

I am attempting to run an Illustrator action w/ applescript. I get dialog boxes (even when running straight from Illustrator) that I just need to hit ‘ok’ to. For example, the action attempts to ‘unlock’ layers. Well, if the layers are unlocked, the action ‘prompts’ that the action is unavailable. I just need to ‘ok’ or ‘continue’

Thanks a lot, here’s what I’ve gotten so far. I’m reading into actually DOING the steps w/in the action via plain applescript (to help avoid the UI stuff).

set mystartfolder to (choose folder with prompt "Choose folder containing your logos")


tell application "Finder"
	activate
	open folder mystartfolder
	
	set startfoldername to name of mystartfolder
	
	set AllFileList to (files of folder mystartfolder) --as list
	
	repeat with thisFile in AllFileList
		
		--if file type of thisFile = "" then
		my JasonsAction(thisFile)
		--end if
		
	end repeat
	
	display dialog "Jason's Action is complete"
	
end tell

on JasonsAction(thisFile)
	set illDoc to thisFile
	tell application "Adobe Illustrator 10"
		open illDoc
		try
			do script "CMYK Logos" from "Refine"
			--on error
			--tell application "Finder" to set label of illDoc to 2
		end try
	end tell
end JasonsAction

ThePunch,

After your do script line add without dialogs.

do script "CMYK Logos" from "Refine" without dialogs

PreTech

That didn’t really work. Still get the dialogs

And, BTW, it appears it’s opening them as .pdf files or something. It’s converting postscript to pdf. It should just be opening them as .eps files.

ThePunch,

try reversing your names for your actions.

do script "Refine" from "CMYK Logos" without dialog

I can’t remember right off hand which is supposed to be first - the action name or the set name. I think this solved the same problem I had with the dialogs. In as far as the files opening as pdf’s I’m not sure what is going on there. Maybe you can do a file type check before opening them.

PreTech

I’m thinking that perhaps the opening as PDF problem is something to do w/ Finder. Because they’re opening in Preview.

As for the dialogs in Illustrator, the user interaction didn’t work. Neither did “without dialogs”

I’m posting what I have so far. I doubt it’s possible, but the way I ‘imagine’ it is placing each step of the action in a ‘try’ statement or something similar.

set mystartfolder to (choose folder with prompt "Choose folder containing your logos")


tell application "Finder"
	activate
	
	
	set startfoldername to name of mystartfolder
	
	set AllFileList to (files of folder mystartfolder) --as list
	
	repeat with thisFile in AllFileList
		
		--if file type of thisFile = "" then
		my JasonsAction(thisFile)
		--end if
		
	end repeat
	
	display dialog "Jason's Action is complete"
	
end tell

on JasonsAction(thisFile)
	set illDoc to thisFile
	tell application "Adobe Illustrator 10"
		set user interaction level to never interact
		open illDoc
		do script "CMYK Logos" from "Refine" without dialogs
		save current document as eps with options {compatibility:Illustrator 10, CMYK PostScript:true, embed all fonts:true, include document thumbnails:true, preview:color Macintosh, flatten output:preserve appearance}
		close current document
		set user interaction level to interact with all
	end tell
end JasonsAction

ThePunch,

Here is a script I wrote that works on my computer. It is not set up as a subroutine but it may help.

tell application "Finder"
	set folderSource to choose folder with prompt "Choose files for overprint."
	set fileList to every file of folder folderSource as alias list
	set folderDest to choose folder with prompt "Choose folder destination."
	set destPath to folderDest as string
	set fileCount to count folder folderSource
	repeat with aFile in fileList
		set fileName to name of aFile
		set newFilePath to destPath & fileName & ".eps"
		tell application "Adobe Illustrator 10"
			activate
			open aFile
			set objectCount to count of every page item of current document
			repeat with i from 1 to objectCount
				set selection to page item i of current document
				-- this is an action set up in AI10. You have to make sure that your names from your actions are EXACTLY the same as in your script.
				do script "Refine" from "CMYK Logos" without dialogs
			end repeat
			save current document in file newFilePath as eps with options {class:EPS save options, compatibility:Illustrator 10, preview:color Macintosh, embed linked files:true, include document thumbnails:true, embed all fonts:true, CMYK PostScript:true, PostScript:level 2} with replacing
			close current document saving no
		end tell
	end repeat
end tell

In the line: do script “Refine” from “CMYK Logos” without dialogs: the way I set it up is CMYK Logos is a Set and Refine is the Action. You may need to reverse this. I believe there needs to be a file path specified for your save statement. When I tried your script with the subroutine, eventhough AI 10 opened the doc fine, it errored out on the action. I don’t know why. Maybe this will help you.

PreTech

Model: dual 1.8 G5
AppleScript: 2.1 (80)
Browser: Safari 412.5
Operating System: Mac OS X (10.4)

ThePunch,

I modified your last bit of code as such:

set mystartfolder to (choose folder with prompt "Choose folder containing your logos")

tell application "Finder"
	activate
	set startfoldername to name of mystartfolder
	set AllFileList to every file of folder mystartfolder as alias list
	repeat with thisFile in AllFileList
		--if file type of thisFile = "" then
		my JasonsAction(thisFile)
		--end if
	end repeat
	display dialog "Jason's Action is complete"
end tell
set illDoc to thisFile
on JasonsAction(illDoc)
	tell application "Adobe Illustrator 10"
		activate
		--set user interaction level to never interact
		open illDoc
		do script "Refine" from "CMYK Logos" without dialogs
		--save current document as eps with options {compatibility:Illustrator 10, CMYK PostScript:true, embed all fonts:true, include document thumbnails:true, preview:color Macintosh, flatten output:preserve appearance}
		close current document saving no
		--set user interaction level to interact with all
	end tell
end JasonsAction

It works here. It seems to be the set AllFileList line.

PreTech

Well, I’m still getting the same error. If the layers aren’t locked, the action tells you that, and then you can click continue.
I got info from the UI Inspector, but I might not be using it properly. I guess my question is, how do you know that no dialogs work on bypassing errors in Illustrator actions? I sure can’t get it to work. Perhaps you aren’t receiving errors because the action is, in fact, not erroring. Use an EPS that the elements are not locked, and include an ‘unlock all’ action in your set. Or have all type in your eps alrady converted to paths, and then have a ‘convert type to paths’ action in the set.

Here’s what I’ve got so far:

tell application "Finder"
	set folderSource to choose folder with prompt "Choose files for overprint."
	set fileList to every file of folder folderSource as alias list
	set folderDest to choose folder with prompt "Choose folder destination."
	set destPath to folderDest as string
	set fileCount to count folder folderSource
	repeat with aFile in fileList
		set fileName to name of aFile
		set newFilePath to destPath & fileName & ".eps"
		tell application "Adobe Illustrator 10"
			activate
			open aFile
			set objectCount to count of every page item of current document
			repeat with i from 1 to objectCount
				set selection to page item i of current document
				-- this is an action set up in AI10. You have to make sure that your names from your actions are EXACTLY the same as in your script.
				
				try
					do script "CMYK Logos" from "Refine" without dialogs
					
				on error
					tell application "System Events"
						tell process "Finder"
							click button "Continue" of window "Adobe Illustrator"
						end tell
					end tell
				end try
				
			end repeat
			save current document in file newFilePath as eps with options {class:EPS save options, compatibility:Illustrator 10, preview:color Macintosh, embed linked files:true, include document thumbnails:true, embed all fonts:true, CMYK PostScript:true, PostScript:level 2} with replacing
			close current document saving no
		end tell
	end repeat
end tell

Ok, I did not make a complex set of actions. How about this. Instead of having an action unlock layers use something like this.

tell application "Adobe Illustrator 10"
	activate
	set thisDoc to current document
	set layerList to every layer of thisDoc
	display dialog layerList as string
	repeat with aLayer in layerList
		if locked of aLayer is true then
			set locked of aLayer to false
		end if
	end repeat
end tell

You can probably convert type to paths in the script also. I don’t remember if I have done that before or not. I’ll look it up.

PreTech

Well, sure, I’d love to be able to do all the steps of the action without using an action. Sure does help w/ portability. I d/led the 500pg Adobe Scripting reference, and it was way too far over my head.

The steps of the action are: (can you guess if it can be accomplished via applescript alone)

Flattening Artwork

Deleting Stray Points

Converting to CMYK

Creating Outlines

Deleting all unused Brushes

Turn Overprint off on strokes and fills

Deleting all unused Swatches

ThePunch,

So far this is the best I can do to address a few of your concerns. This script uses UI scripting. I haven’t figured out how to get stray objects yet and haven’t tried eliminating brushes or swatches. Brushes and swatches are probably not to hard to figure. Anyway here is what I have.

set theFile to choose file with prompt "choose file"
set dun to 0
tell application "Adobe Illustrator 10"
	activate
	--set docRef to make new document with properties {color space:RGB}
	open theFile
	set thisDoc to current document
	set textRef to make new text art item in thisDoc with properties {name:"txt1", contents:"this text", position:{75, 650}}
	set textList to every text art item of thisDoc
	repeat until dun is 1
		try
			set the selection to first text art item of thisDoc
			set thisItem to the selection
			convert to paths thisItem
		on error
			set dun to 1
		end try
		
	end repeat
	get color space of thisDoc
end tell
tell application "System Events"
	tell process "Adobe Illustrator 10"
		tell menu bar 1
			click menu item "CMYK Color" of menu "Document Color Mode" of menu item "Document Color Mode" of menu "File" of menu bar item "File"
		end tell
		tell menu bar 1
			click menu item "Flatten Transparency..." of menu "Object" of menu bar item "Object"
		end tell
	end tell
end tell
tell application "Adobe Illustrator 10"
	set pathCount to count every path item of thisDoc
	repeat with i from 1 to pathCount
		if stroked of (path item i) of thisDoc is true then
			set properties of (path item i) of thisDoc to {stroke overprint:false}
		end if
		if filled of (path item i) of thisDoc is true then
			set properties of (path item i) of thisDoc to {fill overprint:false}
		end if
	end repeat
end tell

Hope this helps.

PreTech

ThePunch,

Here’s some more. This bit eliminates the stray path items. To eliminate stray text items you might do the same routine but select all text art items whose contents is “” or something like that.

set singleList to {}
tell application "Adobe Illustrator 10"
	activate
	set thisDoc to current document
	set pathElim to count path items in thisDoc
	repeat with z from 1 to pathElim
		set the selection to path item z in thisDoc
		set pointCount to (anchor of every path point of path item z of thisDoc)
		set anchorCount to count pointCount
		display dialog "anchor count " & anchorCount
		if anchorCount is less than 2 then
			set properties of path item z of thisDoc to {name:"single" & z}
			get properties of path item z of thisDoc
			set singleList to singleList & ("single" & z)
		end if
	end repeat
	set singleCount to count every item of singleList
	repeat with i from 1 to singleCount
		set theName to item i of singleList
		set the selection to (path item theName) of thisDoc
		delete selection
	end repeat
end tell

There might be some extraneous stuff in the script.

PreTech

PreTech, you don’t need to do all that testing to get stray points.

set strayPts to (every path item whose width is 0 and height is 0)

If you also want stray text boxes (well, most), you can use:

set emptyText to every text frame whose contents is "" or contents is " " or contents is (tab as text) or contents is (return as text)

And you don’t need to make these a selection to delete them. You can delete all of the above listed items in one stroke by creating a variable to contain the first list, then add the second list (of stray text frames) to the first and delete the listed items. To continue with the example code above:

set deleteItems to strayPts & emptyText
delete deleteItems

Same with the overprint settings, these steps can be condensed as follows:

tell application "Illustrator CS"
	tell document 1
		set stroke overprint of every path item whose stroked is true and stroke overprint is true to false
		set fill overprint of every path item whose filled is true and fill overprint is true to false
	end tell
end tell

And converting text frames to outlines:

convert to paths every text frame -- (of document 1)

Deleting unused swatches is difficult, and I suspect it’s gotten worse with CS2 with its ability to apply color to grayscale images. As it is in CS, if you have a placed or embedded 1-bit image with a color applied to it, you can’t figure this out with AppleScript. Also, you can’t check if a path item has a gradient swatch applied. So any AppleScript that attempts to delete “unused” swatches will be unreliable.

In case anyone is interested, I recently posted a bunch of Illustrator cleaning scripts on my site, here.

Edit: for some reason, the page link only works so far, it doesn’t take you to the illustrator_cs section, which is all the way at the end of the page. So just hit your End key and you should see them.

Joseph,

The code you posted probably works well for Ill CS, but ThePunch is working with Ill 10 and it does not seem capable of using a select every statement. It errors any time I have tried to use this.

PreTech

Ah, ignore everything I posted. I have this bad condition where I read everything back to front and got interrupted before I could go over the entire thread.

Ha…so there are that many diff. in scripting between 10 and CS eh?

PreTech…here’s basically where I’ve gone w/ this script. I’ll have to add the stray points and stuff. I’m obviously using a lot of UI here. Just wondering how to reference the ‘fly out’ menus of the swatches palette. Same goes for the Brushes. What menu item? menu? and menu bar item?

Thanks a lot for your help thus far.

set theFile to choose file with prompt "choose file"

tell application "Adobe Illustrator 10"
	activate
	open theFile
	
end tell
tell application "System Events"
	tell process "Adobe Illustrator 10"
		
		------------------------------------UNLOCK ALL
		tell menu bar 1
			click menu item "Unlock All" of menu "Object" of menu bar item "Object"
		end tell
		
		------------------------------------DO A SELECT ALL
		tell menu bar 1
			click menu item "All" of menu "Select" of menu bar item "Select"
		end tell
		
		------------------------------------CONVERT TO RGB
		tell menu bar 1
			click menu item "Convert to RGB" of menu "new menu" of menu item "Colors" of menu "Filter" of menu bar item "Filter"
		end tell
		
		------------------------------------FLATTEN TRANSPARENCY
		tell menu bar 1
			click menu item "Flatten Transparency..." of menu "Object" of menu bar item "Object"
		end tell
		
		------------------------------------CLEAR DIALOG BOXES
		keystroke return
		
		
	end tell
	
end tell

thePunch,

Sorry I haven’t responded. I haven’t had much time lately to devote to any scripting. Work has gotten busy. I haven’t had time to work with this any further yet. I’ll keep trying though.

PreTech

I looks like this has not been posted yet, so…

We had an issue with Illustrator actions that were called by scripts throwing dialogs, even when user interaction was completely turned off. Before I had torn out the last handfull of hair, we discovered a solution.

Go into the Illustrator online help and read the topic “Using the Actions palette.” In the diagram there is an item labeled B, which is used to turn Modal Dialogs in the Actions on/off. These dialogs don’t honor Illustrator’s user interaction setting… So if you expand the listing of steps in an action and uncheck all the modal dialog boxes that are checked - no more dialogs.
:wink:

Mark