Newcomer - Illustrator script save to designated folder - problems

Hello i am fairly new to applescript and am having problems getting this script to work correctly in illustrator.

Basically the script should create a folder on the server and then rename it to the same as the document, then save the document into the folder.

I can get the script to create the folder but not to save the document into it.

It would be useful to if the script could ignore the suffix from the file when creating the folder.

Any help would be appreciated

tell application “Finder”
try
mount volume “afp://xx.x.x.x/COLLATION/”
end try
end tell

global myfolder

set myfolder to “COLLATION:Written:”

tell application “Adobe Illustrator 10.0.3”

set docname to name of document 1 as string
set Finalpath to myfolder & docname

tell application "Finder"
    
    make new folder at folder myfolder with properties {name:docname}
    
end tell

tell application "Adobe Illustrator 10.0.3"
    convert to paths (every text art item of document 1)
end tell

set mynewfile to myfolder & name of document 1 as string
save document 1 in file mynewfile as Illustrator ¬
    with options {class:Illustrator save options, compatibility:Illustrator 8, flatten output:preserve appearance}

end tell

This is how I would have tried with CS. No afp server to test with just tested with folder instead.

tell application "Finder"
	try
		set TheServer to choose folder
		set DestFolder to folder "Written" of folder TheServer
	end try
end tell
tell application "Illustrator CS"
	activate
	set docRef to the current document
	tell docRef
		convert to paths (every text frame of docRef)
		set docName to name of docRef
		set docBaseName to getBaseName(docName) of me
		tell application "Finder"
			make new folder in folder (DestFolder as text) with properties ¬
				{name:docBaseName}
			set newFilePath to (the result as text) & docBaseName & ".eps"
		end tell
	end tell
	save docRef in file newFilePath as eps with options ¬
		{class:EPS save options, preview:color Macintosh, overprint:discard, embed all fonts:true, embed linked files:false, include document thumbnails:true, compatible gradient printing:false, CMYK PostScript:true, PostScript:level 2}
	close docRef without saving
end tell
-- Returns the document name without extension (if present)
on getBaseName(fName)
	set baseName to fName
	repeat with idx from 1 to (length of fName)
		if (item idx of fName = ".") then
			set baseName to (items 1 thru (idx - 1) of fName) as string
			exit repeat
		end if
	end repeat
	return baseName
end getBaseName

Millsy,

Here’s what I came up with based on your script.

tell application "Finder"
    try
        mount volume "afp://xx.x.x.x/COLLATION/"
    end try
end tell

global myfolder

set myfolder to "COLLATION:Written:"


tell application "Adobe Illustrator 10.0.3"
	
	set docname to name of document 1 as string
	display dialog docname
	
	tell application "Finder"
		set Finalpath to ((myfolder as string) & ":" & docname & ":" & docname) as string -- this is where the problem mainly lies. You have to place the docname, which is also the name of the folder, at the end of your file path. There should be no colons after the name otherwise the Finder will think the file is a folder.
		display dialog Finalpath
		make new folder at folder myfolder with properties {name:docname}
		
	end tell
	
	tell application "Adobe Illustrator 10.0.3"
		convert to paths (every text art item of document 1)
	end tell
	
	set mynewfilepath to Finalpath -- This line needs to specify the path to the file.
	display dialog mynewfilepath
	save document 1 in file mynewfilepath as Illustrator ¬
		with options {class:Illustrator save options, compatibility:Illustrator 8, flatten output:preserve appearance} 
	
end tell

Hope this helps.

PreTech

Thanks for the help, I have added a bit more to the script to deal with images but can’t get the images to copy to the same location as the illustrator doc, i am pretty sure it is do with this line – duplicate item myFilePath to Finalpath – i would appreciate any help.

tell application “Finder”
try
mount volume “afp://xx.x.x.x/COLLATION/”
end try
end tell

global myfolder

set myfolder to “Collation:Written:”

tell application “Adobe Illustrator”

set docname to name of document 1 as string

tell application "Finder"
	set Finalpath to ((myfolder as string) & ":" & docname & ":" & docname) as string -- this is where the problem mainly lies. You have to place the docname, which is also the name of the folder, at the end of your file path. There should be no colons after the name otherwise the Finder will think the file is a folder.
	make new folder at folder myfolder with properties {name:docname}
	
end tell

if (count of documents) > 0 then
	activate
	set myRasterItems to every raster item of document 1
	if myRasterItems is not {} then
		repeat with myRasterItem in myRasterItems
			if embedded of myRasterItem is false then
				tell me to doCopyFile(file path of myRasterItem as string)
			end if
		end repeat
	end if
	
	set myPlacedItems to every placed item of document 1
	if myPlacedItems is not {} then
		repeat with myPlacedItem in myPlacedItems
			tell me to doCopyFile(file path of myPlacedItem as string)
		end repeat
	end if
	
	
	tell application "Adobe Illustrator"
		«event ART5EXPD» (every text frame of document 1)
	end tell
	
	set mynewfilepath to Finalpath -- This line needs to specify the path to the file.
	save document 1 in file mynewfilepath as Illustrator ¬
		with options {class:Illustrator save options, compatibility:Illustrator 8, flatten output:preserve appearance}
	
end if

end tell

on doCopyFile(myFilePath)
tell application “Finder”
try
duplicate item myFilePath to Finalpath
end try
end tell
end doCopyFile

Millsy,

In your subroutine it tells the object to copy to Finalpath, but Finalpath is not defined in the subroutine. You either need to specify Finalpath as a global or you need to pass this value from the main script to the subroutine.

tell me to doCopyFile((file path of myPlacedItem as string), Finalpath)

and add this to the subroutine

on doCopyFile(myFilePath, theFinalpath)

Give that a shot.

PreTech

I am still having problems with images not copying to the same location as the illustrator file.

tell application “Finder”
try
mount volume “afp://xx.x.x.x/COLLATION/”
end try
end tell

global myfolder

set myfolder to “Collation:Written:”

tell application “Adobe Illustrator 10.0.3”

set docname to name of document 1 as string

tell application "Finder"
	set Finalpath to ((myfolder as string) & ":" & docname & ":" & docname) as string
	make new folder at folder myfolder with properties {name:docname}
	
end tell

if (count of documents) > 0 then
	activate
	set myRasterItems to every raster item of document 1
	if myRasterItems is not {} then
		repeat with myRasterItem in myRasterItems
			if embedded of myRasterItem is false then
				tell me to doCopyFile((file path of myRasterItem as string), Finalpath)
				
			end if
		end repeat
	end if
	
	set myPlacedItems to every placed item of document 1
	if myPlacedItems is not {} then
		repeat with myPlacedItem in myPlacedItems
			tell me to doCopyFile((file path of myPlacedItem as string), Finalpath)
		end repeat
	end if
	
	
	tell application "Adobe Illustrator 10.0.3"
		convert to paths (every text art item of document 1)
	end tell
	
	set mynewfilepath to Finalpath 
	save document 1 in file mynewfilepath as Illustrator ¬
		
end if

end tell

on doCopyFile(myFilePath, theFinalpath)
tell application “Finder”
try
duplicate item myFilePath to Finalpath
end try
end tell
end doCopyFile

Millsy,

Sorry that I don’t have enough time today to go through all of this, but this is how I modified the script. You’ll have to reset the first part of the script for your extra drive and folder. Look through the code and you’ll see where I changed it. I had to change some of the naming structure for your file name.

Hope this helps.

PreTech

(*tell application "Finder"
	try
		mount volume "afp://xx.x.x.x/COLLATION/"
	end try
end tell*)

global myfolder

set myfolder to ((path to desktop as string) & "theTest:")

set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."


tell application "Adobe Illustrator 10"
	
	set docname to name of document 1 as string
	set foldName to first text item of docname
	display dialog foldName
	tell application "Finder"
		set Finalpath to ((myfolder as string) & foldName & ":" & docname) as string
		make new folder at folder myfolder with properties {name:foldName}
		
	end tell
	
	if (count of documents) > 0 then
		activate
		set myRasterItems to every raster item of document 1
		if myRasterItems is not {} then
			repeat with myRasterItem in myRasterItems
				if embedded of myRasterItem is false then
					tell me to doCopyFile((file path of myRasterItem as string), Finalpath)
					
				end if
			end repeat
		end if
		
		set myPlacedItems to every placed item of document 1
		if myPlacedItems is not {} then
			repeat with myPlacedItem in myPlacedItems
				tell me to doCopyFile((file path of myPlacedItem as string), Finalpath)
			end repeat
		end if
		
		
		tell application "Adobe Illustrator 10"
			convert to paths (every text art item of document 1)
		end tell
		
		set mynewfilepath to Finalpath
		display dialog mynewfilepath
		save document 1 in file mynewfilepath as Illustrator ¬
			
	end if
	set AppleScript's text item delimiters to tid
end tell

on doCopyFile(myFilePath, theFinalpath)
	tell application "Finder"
		set newFile to theFinalpath & "copy.ai"
		try
			duplicate file myFilePath to file newFile
		end try
	end tell
end doCopyFile