Simple saving script

So I’m still learning this art and any assistance with this is much appreciated. All I want to do for right now is get this script to save to a folder alphabeticlly. If this file exists I need a message saying it allready exists and do I want to cancel overwrite or rename. Here is what I have so far

tell application "Adobe Illustrator"
	activate
	set CurrDoc to name of current document
	
	display dialog "Enter File Name" buttons {"OK", "Cancel"} default button "OK" default answer CurrDoc
	
	set happy to the text returned of the result
	
	set h2 to first character of happy
	set filepath to "startup:test:" & h2 & ":" & happy & ".ai"
	set jpgfilepath to "startup:test" & happy & ".jpg"
	set jpgfilename to happy & ".jpg"
	set aifilename to happy & ".ai"
	tell application "Finder"
		
		
		--save current document in file filepath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 10}
		if (the file aifilename of filepath exists) then
			display dialog "this file name is in use"
		end if
	end tell
	display dialog filepath & " saved."
	
	
	--export current document to file jpgfilepath as «constant ePICe330» with options {class:JPEG export options, quality:60, blur:0, horizontal scaling:100, vertical scaling:100, matte:false}
	
	display dialog jpgfilepath & " saved."
end tell

Its working with illustrator and some save options

Any direction would be great

Hi.

I don’t have Illustrator, but for what you want to do right now, this is a start.


if (the file aifilename of filepath exists) then
set theOption to button returned of (display dialog "this file name is in use" & return & return & "choose an option" buttons {"Cancel", "Overwrite", "Rename"} default button "Cancel")

if theOption is "Overwrite" then
	display dialog theOption --save with replacing goes here

else if theOption is "Rename" then
	set newName to text returned of (display dialog "Choose a new name" default answer "")
	
end if


To keep the files alphabetical, set the folder to keep items arranged by name in View Options.

j

Where would I want to put this, after I set all the variables in place of the existing if statement? Thanks for the response by the way.

Hi.

Try this. My comments are all caps to differentiate them from yours. I got it to compile on my computer by changing “Adobe Illustrator” to another application and commenting out “set CurrDoc to name of current document”, but you’ll need to test it.


tell application "Adobe Illustrator"
	activate
	set CurrDoc to name of current document
	
	display dialog "Enter File Name" buttons {"OK", "Cancel"} default button "OK" default answer ""
	
	set happy to the text returned of the result
	
	set h2 to first character of happy
	set filepath to "startup:test:" & h2 & ":" & happy & ".ai"
	set jpgfilepath to "startup:test" & happy & ".jpg"
	set jpgfilename to happy & ".jpg"
	set aifilename to happy & ".ai"
	tell application "Finder"
		
		
		--save current document in file filepath as Illustrator with options {class:Illustrator save options, compatibility:Illustrator 10}
		if not (the file aifilename of filepath exists) then--NOTE THE CHANGE
			
			beep--DO WHATEVER
			
		else --IF THE FILE AFILENAME OF FILEPATH EXISTS
			set theOption to button returned of (display dialog "this file name is in use" & return & return & "choose an option" buttons {"Cancel", "Overwrite", "Rename"} default button "Cancel")
			
			
			if theOption is "Overwrite" then
				display dialog theOption --SAVE WITH REPLACING GOES HERE
				
			else if theOption is "Rename" then
				set newName to text returned of (display dialog "Choose a new name" default answer "")
				
			end if
		end if
	end tell
	display dialog filepath & " saved."
	
	
	--export current document to file jpgfilepath as «constant ePICe330» with options {class:JPEG export options, quality:60, blur:0, horizontal scaling:100, vertical scaling:100, matte:false}
	
	display dialog jpgfilepath & " saved."
end tell

Hi Starfox

not sure if this is exactly what you want but you might be able to tweak it for your needs.

tell application "Illustrator CS"
	activate
	set CurrDoc to name of current document
end tell
tell application "Finder"
	activate
	display dialog "Enter File Name" buttons {"OK", "Cancel"} default button "OK" default answer CurrDoc
	set happy to the text returned of the result
	set fileName to happy as string
	set filepath to (choose folder)
	set destinationPath to filepath as string
	set jpgfilepath to destinationPath & fileName
	if not (exists file jpgfilepath) then
		beep
		display dialog "Does Not Exist!!"
	else
		set theOption to button returned of (display dialog "this file name is in use" & return & return & "choose an option" buttons {"Cancel", "Overwrite", "Rename"} default button "Cancel")
		if theOption is "Overwrite" then
			display dialog theOption
			tell application "Illustrator CS"
				activate
				save current document in file jpgfilepath as Illustrator ¬
					with options {class:Illustrator save options ¬
					, compatibility:Illustrator 10}
				close current document saving no
			end tell
		else if theOption is "Rename" then
			set newName to text returned of (display dialog "Choose a new name" default answer "")
			tell application "Illustrator CS"
				activate
				save current document in file jpgfilepath as Illustrator ¬
					with options {class:Illustrator save options ¬
					, compatibility:Illustrator 10}
				close current document saving no
				tell application "Finder"
					set name of file fileName of alias destinationPath to newName & ".ai"
				end tell
			end tell
		end if
	end if
end tell

you will have to recompile for your version of illustrator