how do I add variables to a simple script?

Hi,

I am sorry to say that I know almost nothing about AppleScript. I have a great and helpful one, posted below, that I got from a coworker and I need to change it slightly. It is meant to turn the slugline layer off in maps created in Adobe Illustrator CS. The problem is that the slugline is called all different things: “ID”, “map id”, “slugline”, “slug”, etc. Is there a way to edit the script below so that it tries all possible names before giving up? This is the line I need to add the other possible names to:

tell current document
set theLayer to layer “Slugline”
set visible of theLayer to false

Thanks very much.

Jennifer

tell application "Finder"
	set sourceFolder to choose folder with prompt "Select the folder with files for conversion."
	set destFolder to choose folder with prompt "Select the destination folder."
	set fileList to every file of folder sourceFolder as alias list
	set fileCount to count folder sourceFolder
	if fileCount is not 0 then
		repeat with aFile in fileList
			set fName to name of aFile
			set newFilePath to destFolder & fName as string
			tell application "Illustrator CS"
				activate
				open aFile without dialogs
				tell current document
					set theLayer to layer "Slugline"
					set visible of theLayer to false
				end tell
				save current document in file newFilePath as eps
				--with options {class:EPS save options, compatibility:Illustrator 9, preview:color Macintosh, embed linked files:false, include document thumbnails:false, embed all fonts:false, CMYK PostScript:true, PostScript:level 2} with replacing
				close current document saving no
			end tell
		end repeat
	end if
end tell

Model: Mac G5
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Give something like a try

set slug_names to {"ID", "mapid", "slugline", "slug"} -- etc.
tell application "Finder"
	set sourceFolder to choose folder with prompt "Select the folder with files for conversion."
	set destFolder to choose folder with prompt "Select the destination folder."
	set fileList to every file of folder sourceFolder as alias list
	set fileCount to count folder sourceFolder
	if fileCount is not 0 then
		repeat with aFile in fileList
			set fName to name of aFile
			set newFilePath to destFolder & fName as string
			tell application "Illustrator CS"
				activate
				open aFile without dialogs
				tell current document
					repeat with a_slug_name in slug_names
						try
							set theLayer to layer a_slug_name
							set visible of theLayer to false
							exit repeat
						end try
					end repeat
				end tell
				save current document in file newFilePath as eps
				--with options {class:EPS save options, compatibility:Illustrator 9, preview:color Macintosh, embed linked files:false, include document thumbnails:false, embed all fonts:false, CMYK PostScript:true, PostScript:level 2} with replacing
				close current document saving no
			end tell
		end repeat
	end if
end tell

Jennifer:

James beat me to the first answer but here’s a little quicker method… save yourself a loop or two ! :smiley: (Note: This does not hide SubLayers even if their name is found in the list. Alternately, a SubLayer with a nonlisted name will be hidden if it’s parent has a listed name. FYI.)


-- Add to this variable as you see fit. It is case insensitive so it WILL find "SlugLiNE".
set slug_names to {"ID", "mapid", "slugline", "slug"} -- etc. 
tell application "Finder"
   set sourceFolder to choose folder with prompt "Select the folder with files for conversion."
   set destFolder to choose folder with prompt "Select the destination folder."
   set fileList to every file of folder sourceFolder as alias list
   set fileCount to count folder sourceFolder
   if fileCount is not 0 then
       repeat with aFile in fileList
           set fName to name of aFile
           set newFilePath to destFolder & fName as string
           tell application "Illustrator CS"
               activate
               open aFile without dialogs
               tell current document
		try -- Here we just tell those layers to hide all at once instead of walking them in a repeat loop.
			set visible of (every layer whose name is in layerNames) to false
		end try
	end tell
               save current document in file newFilePath as eps
               --with options {class:EPS save options, compatibility:Illustrator 9, preview:color Macintosh, embed linked files:false, include document thumbnails:false, embed all fonts:false, CMYK PostScript:true, PostScript:level 2} with replacing
               close current document saving no
           end tell
       end repeat
   end if
end tell

I don’t know if you’re in a position to dictate procedures but you should really look at making this more consistent. I develop / implement workflows which often include scripting as part of the system. Consistency is the watchword. Your’s is a simple example but it’s still an inefficiency that has to be error trapped against. If everyone named it “slugLine”, the scripting would be even easier. And as much as whiners want to hold on to “habit” over efficiency let them (or your superior) know that this consistency will not only make scripts easier to write and implement but there’s less chance of them breaking. Down off my soapbox now.:stuck_out_tongue:

Best Regards,
Jim Neumann
BLUEFROG

Blue, I’m sure you meant this


set visible of (every layer whose name is in slug_names) to false

=)

Nice catch, James. :stuck_out_tongue: (I had a small core written when I saw yours and thought, “Don’t forget to rename your variable to match.” and then promptly forgot!)

-Jim

Thanks so much, Jim and James! You’ve saved me hours of annoying headaches. Also, I couldn’t agree with you more, Jim. I fight for file naming consistency until I’m blue in the face and get nowhere. I work for a large publishing co. and everything is outsourced. It’s close to impossible to get anyone to pay attention to any of the file naming conventions we set up. It’s really a drag and I waste so much time renaming and fixing what I get in at the end of the projects.

Thanks again.

Jennifer