script makes illustrator crash

tell application “Illustrator CS”
activate
set myDocument to current document
set ruler origin of document 1 to {0.0, 0.0}
set myDate to (current date) as string
set myName to make new text frame in current document with properties {position:{524, 767}, contents:“Dan Fox”}
set fileName to name of current document
set fileName to make new text frame in current document with properties {position:{524, 738}, contents:fileName}
make new text frame in current document with properties {position:{524, 727}, contents:myDate}
set selection of myDocument to {myDate}
end tell

Everything works eccept the last line I want to keep some text selected and lock it down.

It woun’t make the selection and I can’t find the command to lock it down.
illustrator just crashes

Any Advice

Model: powermac g5
AppleScript: 2.1
Browser: Internet Explorer 6.0
Operating System: Mac OS X (10.4)

The problem is that Illustrator doesn’t know how to handle this line:

 set selection of myDocument to {myDate}

becouse there is no reference to the text frame that you want to select. By setting a variable in the make line of the text item you want to select the object reference of the text frame is saved to the variable. Using that variable will now act as if you were “telling” the object referenced in the variable.

set NewSelection to make new text frame in myDocument with properties {position:{524, 727}, contents:(current date) as string}

Using this information on the object model that Adobe Applications use you could reduce the number of lines that you have to the following:

tell application "Illustrator CS"
	activate
	set myDocument to current document
	set ruler origin of myDocument to {0.0, 0.0}
	set myName to make new text frame in myDocument with properties {position:{524, 767}, contents:"Dan Fox"}
	set fileName to make new text frame in myDocument with properties {position:{524, 738}, contents:(name of myDocument) as string}
	set NewSelection to make new text frame in myDocument with properties {position:{524, 727}, contents:(current date) as string}
	set selection of myDocument to NewSelection
end tell

Now if the goal was simply to lock the items as you created them then you need to add the locked property to the make line:

tell application "Illustrator CS"
	activate
	set myDocument to current document
	set ruler origin of myDocument to {0.0, 0.0}
	set myName to make new text frame in myDocument with properties {position:{524, 767}, contents:"Dan Fox", locked:true}
	set fileName to make new text frame in myDocument with properties {position:{524, 738}, contents:(name of myDocument) as string, locked:true}
	set NewSelection to make new text frame in myDocument with properties {position:{524, 727}, contents:(current date) as string, locked:true}
end tell

Wow man you explained that well. Thanks

I was going about this all wrong. I didnt know to include the locked command within the properties. I was trying to select the text and then lock it down.

I’m still a little confused about how to word things. For Instance how can I change the document setup. Customers send me art all day, the goal is to run a script that will set the document and page to us letter with no margins, place the file name in the lower left corner of the page, prompt to a save dialog, then put the new file name, the date, and my name in the top right corner. Oh yeah and lock down all this new text.

I pretty much have it all together (thanks to you guys) Just changing the doument and page properties. I’m not so good at finnding what I need in the dictionary.

It takes a while to learn how to word things for a specific application, and how to find meaningfull information out of most dictionaries. Every application is different as well, becouse the programers have a different mindset and different object models for the applications. Adobe apps are fairly well done once you understand how to work with them, and their object model. I find that it still takes time playing around with scripts to find out how to get the desired effect.

Ilustrator’s page height and width are read only properties, at least in the document preferences, so you can’t change them using the document prefs. If I have some time I will dig around a little and see if I can find out more on this. Illustrator’s save command does not use prompts so you might need to use a choose folder command in conjunction with a display dialog command:

set MyPath to (choose folder) as string
set myName to display dialog "Enter the new file name:" default answer ""
set myName to text returned of myName
tell application "Illustrator CS"
	save document 1 in (MyPath & myName) as Illustrator
end tell

The text placement you have a handle on. A pet peave of mine as a designer and former production artist, the slugs get in the way of placing, sizing, and centering the art in the page layout program. I would have the text placed on a seperate layer then lock and hide it. Create another to print those files that opens them, turnes the layer on and prints them.

Thanks For The Help Man!!!:d You Rock!!!