Noobie needs help scripting Illustrator CS: Getting an error???

Hey everyone I’m trying to run an action using applescript with Illustrator CS (OSX). But when I try to run the script I get an error message: The object “Play Action” is not currently available

What I want to do is:

  1. Choose folder from desktop to batch (has Illustrator files)
  2. When each document opens hide layers “SLUG” and “SCREEN”
  3. Run action “SLF CS” from “PRT/APRT” (these actions will make eps/jpeg files that are already designated to folders on my desktop)

Thanks this is what I have thus far. Still learning as you can see…

tell application “Illustrator CS”
set properties of layer named “SLUG” of document to {visible:false}
set properties of layer named “SCREEN” of document to {visible:false}
do script “SLF CS” from “PRT/APRT” without dialogs
end tell

ryo14:

You have to tell AI which document. Document 1 (the frontmost) or current document will work.

FYI: Many times when I know I will be doing operations on a document I will start the script "tell document 1 of app “Illustrator CS”. This way I’m already talking directly to the document from square one.

Have fun,
Jim Neumann
BLUEFROG

P.S. Don’t have the actions palette open when you run scripts calling actions. You may get unexpected results (or no results at all - which I guess is still unexpected!)

Along with what BLUEFROG mentioned…

No need to mess with ‘set properties … {visible:false}’ just ‘set visible of layer X to false’ will do.

You’ll want to reference ‘layer “SLUG”’ not ‘layer named “SLUG”’. Referring to the layer this (correct) way assumes two things: the layer exists, and it exists as a topmost layer, i.e. not a sublayer. Though this may be safe and certain at the moment, it may not be in the future and isn’t a very robust method. If SLUG is a sublayer the following command will error:

tell document 1 to set slugLayer to layer "SLUG"

So in order to be certain you can find the layer regardless of where you or someone else might’ve placed it you can try the above and if it fails, iterate through each top layer looking for the matching layer. And even this isn’t complete since AI can have multiple layers with the same exact name.

I tested the below code with a document “test.ai” with two sublayers named “SLUG” and it worked fine (making each SLUG layer invisible). It wasn’t an action though.

setLayerVisibility("test.ai", "SLUG", false)

on setLayerVisibility(doc, layerRef, vis)
	tell application "Adobe Illustrator"
		if class of doc is string or class of doc is integer then set doc to document doc
		if class of layerRef is string then set layerRef to my layerRefForNameInstance(doc, layerRef, 0)
		if class of layerRef is not list then
			set visible of layerRef to vis
		else
			repeat with thisLayerInstance in layerRef
				set visible of thisLayerInstance to vis
			end repeat
		end if
	end tell
end setLayerVisibility

on layerRefForNameInstance(doc, layerName, instance)
	tell application "Adobe Illustrator"
		if class of doc is string or class of doc is integer then set doc to document doc
		tell doc
			try
				set targetLayer to layer layerName
				return targetLayer
			on error
				set topLayers to layers
				set foundInstance to 0
				set allInstances to {}
				repeat with thisLayer in topLayers
					if exists layer layerName of thisLayer then
						set foundInstance to foundInstance + 1
						if foundInstance = instance then return layer layerName of thisLayer
						set end of allInstances to layer layerName of thisLayer
					end if
				end repeat
				if instance < 0 then return item instance of allInstances
				if instance is 0 then return allInstances
			end try
		end tell
	end tell
end layerRefForNameInstance

I should note that the layerRefForNameInstance handler is shortened here. If there is a topmost layer named layerName, it should actually check if it’s the requested instance before returning.

Hey everyone, thanks for the info. I’m still getting an error though? I’m just simply trying to run an action through a script and I’m getting the same thing: object “play action” is currently not available? I closed the actions palette…

tell application “Illustrator CS”
tell current document
do script “EXPORT JPG” from “BW”
end tell
end tell

Once I get this squared away, can I process a group of files from a specified folder or do I have to use only open docs?

Thanks again…

The command is correctly formatted. Are you certain the action “EXPORT JPG” exists in the action set “BW”? If I test the command with non-existing actions and/or action sets, I get the AI dialog message you mention. It’s also case sensitive.

Hey everyone my mistake, I had the listing for the action name backwards! :expressionless: Call me a Noobie x2…