Properties and remembering

I wrote a script for Illustrator CS a while back. This script creates a template. The script works well. Over time I have tinkered with it adding features and such. One problem I had was if I had Ill 8 open when the script was run it would target Ill 8 instead of CS. So I added an on run end run in the script so I could make sure CS was the targeted app.

The original script had a property associated with it. This property is a list of customers. If a customer is not in the list, I add the name, sort the list and then save the new list in the property so next time I run the script (saved as an app) I could choose the customer if they were in the list. Now that I have had to change the script, because of the above explanation, the property is not being saved as it was before. So the question is how can I save the property as a list that can be changed as I add names. Here is the basic script for the list part of the script.

--property custList : {"AAA_Not Here", "Cust1", "Cust2"}

on run
	run script thisScript
end run

script thisScript
	property custList : {"AAA_Not Here", "Cust1", "Cust2"} -- I tried placing the property here but the result is the same. Always just what the property defines here.
	set temp to {}
	set sorted to {}
	choose from list custList
	set cust to the result as text
	if cust = "AAA_Not Here" then
		display dialog "Who is the customer?" default answer ""
		set cust to text returned of the result
		if cust is not in custList then
			set custList to custList & cust
		end if
	end if
	set theCount to count custList
	repeat with k from 1 to theCount
		repeat with anItem in custList
			set theChk to anItem
			repeat with i from 1 to (count custList)
				if theChk is not less than item i of custList then
					set theChk to item i of custList
				end if
			end repeat
		end repeat
		set sorted to sorted & theChk
		repeat with i from 1 to (count custList)
			if item i of custList is not theChk then
				set temp to temp & item i of custList
			end if
		end repeat
		set custList to temp
		set temp to {}
	end repeat
	set custList to sorted
	return custList
end script

If you take out the on run and the script end script parts the list is remembered as desired.

Thanks.

PreTech

I didn’t really understand why you needed to add the on run handler, but you could give this a try:

property custList : {"AAA_Not Here", "Cust1", "Cust2"}

on run
	thisScript()
end run

on thisScript()
	set temp to {}
	set sorted to {}
	choose from list custList
	set cust to the result as text
	if cust = "AAA_Not Here" then
		display dialog "Who is the customer?" default answer ""
		set cust to text returned of the result
		if cust is not in custList then
			set custList to custList & cust
		end if
	end if
	set theCount to count custList
	repeat with k from 1 to theCount
		repeat with anItem in custList
			set theChk to anItem
			repeat with i from 1 to (count custList)
				if theChk is not less than item i of custList then
					set theChk to item i of custList
				end if
			end repeat
		end repeat
		set sorted to sorted & theChk
		repeat with i from 1 to (count custList)
			if item i of custList is not theChk then
				set temp to temp & item i of custList
			end if
		end repeat
		set custList to temp
		set temp to {}
	end repeat
	set custList to sorted
	return custList
end thisScript

Sälli,

Well, that was just too easy.:rolleyes:
Anyway, the reason I needed to do this was, if I had Illustrator 8 open and tried to run the script (saved as an app) it would change this:

tell application "Illustrator CS"
do actions
end tell

into this:

tell application "Adobe® Illustrator 8.0.1"
do actions
end tell

and would error. So I had to do this to ensure that the proper program was used.

property custList : {"AAA_Not Here", "Loctite", "Tom's"}
property Ill : (path to applications folder as Unicode text) & "Adobe Illustrator CS:Illustrator CS.app"
property oldIll : "MacIntosh HD G52:Applications (Mac OS 9):Adobe Illustrator® 8.0:Adobe Illustrator® 8.0.1"

on run
	tell application "System Events"
		if exists process "Adobe Illustrator® 8.0.1" then tell application "Illustrator CS" to quit
	end tell
	tell application "System Events"
		if not (exists process "Illustrator CS") then
			tell application Ill to launch
		end if
	end tell
	run script thisScript
end run

Anyway, Thanks! :smiley:

PreTech

OK, now it makes sense. Goog thing you got it working.