Prompt With Default Folder Path

Hi, Jeff. If the original script saves without complaining, then so should my last one with the two suggested amendments. The only difference in their save code is that ‘newFile’ is an HFS path in the original, that’s turned into a file specification by placing the word ‘file’ in front of it. In mine, it is a file specification as returned by ‘choose file name’. Here’s the complete, corrected script again, in case anything went astray earlier:

on main()
	tell application "Illustrator CS"
		activate
		if ((count documents) > 0) then
			-- Get the path to the current document, if such a path exists.
			try
				set origPath to file path of current document as Unicode text
				-- Rather uselessly, Script Editor and TextEdit return POSIX paths here.
				-- Here's a trap in case Illustrator does the same.
				try
					origPath as alias
				on error
					set origPath to origPath as POSIX file as Unicode text
				end try
			on error
				set origPath to ""
			end try
			
			-- Set a default save name for the document.
			try
				set currentName to name of current document
				if (currentName does not end with ".eps") then set currentName to currentName & ".eps"
			on error
				set currentName to "Untitled.eps"
			end try
			
			-- Prompt for a save name and location. Default to the document's current location
			-- if it has one, otherwise to the last one used by the application.
			if ((count origPath) > 0) then
				set newFile to (choose file name with prompt "Save this document as." default location (origPath as alias) default name currentName)
			else
				set newFile to (choose file name with prompt "Save this document as." default name currentName)
			end if
			
			-- Check that the ".eps" hasn't been lost from the name.
			repeat until ((newFile as Unicode text) ends with ".eps")
				set newFile to (choose file name with prompt "The name you choose must have have an ".eps" extension. Save this document as." default name currentName)
			end repeat
			
			-- Create the new file if it doesn't exist.
			try
				open for access newFile
				close access newFile
			end try
			
			-- Save the document to it.
			save current document in newFile as eps with options {class:EPS save options, preview:color Macintosh, embed all fonts:true, embed linked files:false, include document thumbnails:true, compatible gradient printing:true, CMYK PostScript:true, overprint:discard, PostScript:level 3}
			
		end if
	end tell
end main

main()

But don’t hesitate to speak up if it still doesn’t work properly. :slight_smile:

UNBELIVEABLE!!!
I haven’t found a flaw yet. This is so Awesome. And it couldn’t be better timing. I am going to have testers use this tomorrow. I was going to have them test the previous script, taking notes on the difficulties of setting the file path (when necessary). But now, thanks to you and Jim, this is a non issue!
Seriously Nigel, I owe you a great thanks. You have been a terrific help and very diligent and patient.
Do you mind if I test this some more in the next few days, and report and odd behavior if it happens to occur? If yes, should I just add it to this thread?
I don’t foresee any issues. This script is the bomb.
Not to burden you more, I was wondering if you see a harm in the script I included in the beginning? It was one I didn’t receive help with. It is just an indicator warning when an Illustrator file is set to RGB. (It isn’t meant to automate, or convert, just a warning) It seems to work just fine. But I don’t know if I included extraneous code (I used an InDesign Applescript book for help). No need to reply, unless you feel it is a detriment and/or would cause problems.
Once again, THANK YOU!!
-jeff

on main()
tell application “Illustrator CS”
activate
try
set CurrentMode to color space of current document
end try
if CurrentMode = RGB then
set userResponse to (display dialog “RGB ” Click No (Then Fix File)” buttons {“Yes”, “No”} default button 2 with icon 2)
if button returned of userResponse is “No” then return
end if
if ((count documents) > 0) then
– Get the path to the current document, if such a path exists.
try
set origPath to file path of current document as Unicode text
– Rather uselessly, Script Editor and TextEdit return POSIX paths here.
– Here’s a trap in case Illustrator does the same.
try
origPath as alias
on error
set origPath to origPath as POSIX file as Unicode text
end try
on error
set origPath to “”
end try

		-- Set a default save name for the document.
		try
			set currentName to name of current document
			if (currentName does not end with ".eps") then set currentName to currentName & ".eps"
		on error
			set currentName to "Untitled.eps"
		end try
		
		-- Prompt for a save name and location. Default to the document's current location
		-- if it has one, otherwise to the last one used by the application.
		if ((count origPath) > 0) then
			set newFile to (choose file name with prompt "Save this document as." default location (origPath as alias) default name currentName)
		else
			set newFile to (choose file name with prompt "Save this document as." default name currentName)
		end if
		
		-- Check that the ".eps" hasn't been lost from the name.
		repeat until ((newFile as Unicode text) ends with ".eps")
			set newFile to (choose file name with prompt "The name you choose must have have an ".eps" extension. Save this document as." default name currentName)
		end repeat
		
		-- Create the new file if it doesn't exist.
		try
			open for access newFile
			close access newFile
		end try
		
		-- Save the document to it.
		save current document in newFile as eps with options {class:EPS save options, preview:color Macintosh, embed all fonts:true, embed linked files:false, include document thumbnails:true, compatible gradient printing:true, CMYK PostScript:true, overprint:discard, PostScript:level 3}
		
	end if
end tell

end main

main():smiley:

No and yes respectively. :slight_smile:

If the extra stuff does what’s required, it shouldn’t harm the rest of the script. The last ‘if’ line quoted above (the resumption of my own contribution) is meant to stop anything happening in the unlikely event of someone trying to run the script without any Illustrator documents open. You might like to move your code to immediately after that line.

Another minor point is that if there’s a problem getting the ‘color space of current document’, your ‘try’ block will recover from the error OK, but the variable CurrentMode won’t be set. So the script will error anyway when it tries to read the variable in the next line. You could move the ‘end try’ down to the end of your code so that the rest of it’s skipped if there’s a problem.

Occam’s Razor wins again! I guess this is what happens when you go up against the venerable Nigel Garvey!:stuck_out_tongue: (Just Kidding!) Glad you’re getting somewhere, Jeff.

Later,
Jim

Sorry all for delay.
I was busy all day making movies regarding this, and writing documentation on how great this script is!!!
Now the fun part of having it tested and used in our workflow :slight_smile:
Nigel, thank you for the new advice. I will make those amendments.

Once again. You have all really helped me tremendously! I enjoyed being a nuisance, testing your stamina. I can’t believe how patient you guys are.

Thanks so very much,
jeff

Hello, it’s me again.
Don’t be alarmed, everything is working great on that script. I do have one very minor request. Believe me this is no “show stopper.” (So if you don’t respond, no worries)
With that being said, this is the request dealing with an operator changing a file’s name.

Scenario:
An operator opens a pre-saved document called PizzaChef_4c.eps. (The “_4c” stands for four color).

An operator changes it to one color to accommodate a one color print run.

An operator activates this script, evoking the Save As field, and folder path selection.

In the “Name” field the operator deletes the old name “PizzaChef_4c.eps” and then types the new name “PizzaChef_BK” (Notice, they left off the “.eps”)

This results in an additional dialog box that prompts the user that “.eps” must be appended to the filename, and it automatically appends “.eps” to the name in the “Name” field. (ALL VERY GOOD THINGS). But, in that dialog box, the “Name” field’s text defaults back to the original filename. Ex: PizzaChef_4c.eps.

So it is possible that the operator may not realize the difference in names “_4c” vs. “_BK”.

It would be ideal if that second dialog box’s “Name” field could be populated with the text that was previously entered in the “Name” field ” In other words, the name that they forgot to place “.eps” at the end of: “PizzaChef_BK”

“OMG, what kind of operators do you have working over there?” you may ask. Well, some are very good, but some are completely new to dealing with such programs, and don’t know what a file extension is. I wish I didn’t have to safeguard against such blatant human error, but it does happen :frowning:

If you can help, GREAT. If not, I still want to give another thanks to this Incredible script you wrote!!!

on main()
	tell application "Illustrator CS"
		activate
		if ((count documents) > 0) then
			try
				set CurrentMode to color space of current document
				if (CurrentMode = RGB) then
					set userResponse to (display dialog "RGB  ” Click No (Then Fix File)" buttons {"Yes", "No"} default button 2 with icon 2)
					if (button returned of userResponse is "No") then return
				end if
			on error
				-- Optionally do something here in the event of an error.
			end try
			
			-- Get the path to the current document, if such a path exists.
			try
				set origPath to path of current document as Unicode text
				-- Rather uselessly, Script Editor and TextEdit return POSIX paths here.
				-- Here's a trap in case Illustrator does the same.
				try
					origPath as alias
				on error
					set origPath to origPath as POSIX file as Unicode text
				end try
			on error
				set origPath to ""
			end try
			
			-- Set a default save name for the document.
			try
				set currentName to name of current document
				if (currentName does not end with ".eps") then set currentName to currentName & ".eps"
			on error
				set currentName to "Untitled.eps"
			end try
			
			-- Prompt for a save name and location. Default to the document's current location
			-- if it has one, otherwise to the last one used by the application.
			if ((count origPath) > 0) then
				set newFile to (choose file name with prompt "Save this document as." default location (origPath as alias) default name currentName)
			else
				set newFile to (choose file name with prompt "Save this document as." default name currentName)
			end if
			
			-- Check that the ".eps" hasn't been lost from the name.
			repeat until ((newFile as Unicode text) ends with ".eps")
				set newFile to (choose file name with prompt "The name you choose must have have an ".eps" extension. Save this document as." default name (newFile as Unicode text))
			end repeat
			
			-- Create the new file if it doesn't exist.
			try
				open for access newFile
				close access newFile
			end try
			
			-- Save the document to it.
			save current document in newFile as eps with options {class:EPS save options, preview:color Macintosh, embed all fonts:true, embed linked files:false, include document thumbnails:true, compatible gradient printing:true, CMYK PostScript:true, overprint:discard, PostScript:level 3}
			set path of current document to POSIX path of newFile
		end if
	end tell
end main

main()

Your operators may get a little annoyed that the script complains about the lack of an “.eps” extension without actually doing something about it itself. :wink: But if they’ve made one goof, it’s possible there may be others they need to put right at the same time, which only they will be able to recognise.

I hope I haven’t made any myself while reconstructing this script… :rolleyes:

Nigel,
Thanks a million!
This works perfectly. Btw, I did modify that line slightly adding (& “.eps”) So it reads:
set newFile to (choose file name with prompt “The name you choose must have an “.eps” extension. Save this document as.” default name ((newFile as Unicode text) & “.eps”))

This way .eps always gets automatically appended to the name they entered. (It seems to work?). I don’t feel the operators will be confused that it doesn’t continue to save even though it is correct named at that point. Reason being, the way the “Name” becomes highlighted in the field, and not the “.eps” is enough visual to pinpoint the error. The fact that they have to hit save again is actually a blessing in disguise, for they need to understand the importance of extensions”especially for Photoshop files. (I am basically restating what you were refering to)

Btw, why do I get the feeling you were testing to see if I was doing my homework :slight_smile:
I became nervous when this script couldn’t find the file and produced that error. Luckily it was just due to that bottom line still “latching on” and in the script:
set path of current document to POSIX path of newFile

Nigel thank you so much for all of your help. This script really is INCREDIBLE!!!

jeff

Ah yes. I’d forgotten about that line. Sorry. Glad you were able to sort it out. :slight_smile: