gobbledegook!! on end of file name when saving file in illustrator

Hi
When i’m saving a file in illustrator, even if the name is fairly long it saves down fine, but when i do a save
via an applescript i get part of the file name then a load of garbage on the end.
anyone no how to stop this from happening?

tell application "Finder"
	set doc_path to choose folder with prompt "Choose destination."
end tell
tell application "Illustrator CS"
	activate
	save current document in doc_path with options {compatibility:Illustrator 11}
end tell

cheers

I may be stating the obvious but you need to add a file name to the save command, your choose folder only returns a file path without a name to save the file under, try:

   save current document in doc_path & "NewFile" with options {compatibility:Illustrator 11}

replacing “NewFile” with the name that you want to save the file as.

Hi Jerome
tried inputting that line but just received an error.
the above script was just something small to give an idea.
Here’s the full script i’m working on.

property x : {day of (current date)}
property y : {month of (current date) as number}
property z : {year of (current date)}
property myfiletypes : {".ai"}
on open myfinderitems
	set pdfsgohere to choose folder with prompt "Pick where you want these pdf's to go"
	tell application "Finder"
		--my email_mail()
		repeat with myfinderitem in myfinderitems
			tell application "Finder" to set myitemisfolder to (kind of myfinderitem = "folder")
			if myitemisfolder then
				tell application "Finder" to set myfoldercontents to (every item of myfinderitem)
				open myfoldercontents
			else
				tell application "Finder" to set myitemextension to "." & (name extension of myfinderitem) as string
				if myfiletypes contains myitemextension then
					tell application "Illustrator CS"
						open myfinderitem as alias
						set docname to name of document 1 as string
						do script "Delete Unused Palette Items" from "Default Actions" without dialogs
						tell application "Finder" to set Finalpath to {pdfsgohere & x, "-" & y, "-" & z & " " & docname} as string
						tell application "Illustrator CS"
							activate
							save current document in Finalpath as pdf ¬
								with options {class:PDF save options ¬
								, compatibility:Acrobat 6 ¬
								, acrobat layers:true ¬
								, preserve editability:false ¬
								, color compression:automatic JPEG low ¬
								, compress art:true ¬
								, optimization:true ¬
								, page info:true ¬
								, registration marks:true}
							--, PDF preset:"Hi-Res pdf"}
							close current document saving no
						end tell
					end tell
				end if
			end if
		end repeat
	end tell
end open

most of the illustrator files i’ll be dealing with have long names, i need them to keep there original name and add the date then save as pdf
depending on how long the names are sometimes it converts them sometimes it ignores them. if the name is short this script works fine…!
even though the file names are long if i save these down manually in illustrator i don’t get the junk on the end of the file,
i’m not going over the allotted amount of characters allowed in osX, so not sure why this is happeniing…
cheers

Hi, both.

I don’t have an answer for Pidge1’s problem, but just to comment on what’s gone before:

In Pidge1’s script, the value of doc_path is the alias returned by ‘choose folder’. Concatenating the string “NewFile” to it will produce a list, not a string or Unicode text.

Is this what you mean? These properties aren’t changed anywhere in the script, so every time it’s run, their values will be lists containing respectively the day number, the month number, and the year number of the date on which the script was compiled.

Hope these points are of interest. :slight_smile:

Hi

Thanks Nigel That answers a question i had.
i came back to this script after a few days and when i ran it it gave me the date 4 days prior,
that must just be my scripting inexperience.
So if i loose the properties and just put the day of current date bit etc…or is there a better way,
any help would very welcome thanks

pidge1

Hi, pidge1.

Since everything else seems to be within your open handler, you could simply start off with something like this:

property myfiletypes : { ".ai" }

on open myfinderitems
	set today to (current date)
	set x to today's day
	set y to today's month as integer
	set z to today's year
	set pdfsgohere to choose folder with prompt "Pick where you want these pdf's to go" 
	-- Rest of script

Good luck with the other problem. :slight_smile:

Thanks Nigel
I’ll give that a go.

As for my other problem still not sure, think it might just be something i have to live with.

cheers

Pidge1,

I don’t know if this is the problem or not. Trying to troubleshoot scripts like this is difficult sometimes. I took this part of your script and tried this and have a problem with the file being saved because the file does not already exist.

set x to {day of (current date)}
set y to {month of (current date) as number}
set z to {year of (current date)}
set pdfsgohere to choose folder with prompt "Pick where you want these pdf's to go"
tell application "Illustrator CS"
	set docname to name of current document
	tell application "Finder" to set Finalpath to {pdfsgohere & x, "-" & y, "-" & z & " " & docname} as string
	save current document in Finalpath as pdf ¬
		with options {class:PDF save options ¬
		, compatibility:Acrobat 6 ¬
		, acrobat layers:true ¬
		, preserve editability:false ¬
		, color compression:automatic JPEG low ¬
		, compress art:true ¬
		, optimization:true ¬
		, page info:true ¬
		, registration marks:true}
end tell
display dialog Finalpath

When I remove the “tell application ‘Finder’” part and just set it to "set Finalpath to " it works. Of course it did not save anything at all the first time, so I don’t know for sure that this is the problem but it might be worth a try.

set x to {day of (current date)}
set y to {month of (current date) as number}
set z to {year of (current date)}
set pdfsgohere to choose folder with prompt "Pick where you want these pdf's to go"
tell application "Illustrator CS"
	set docname to name of current document
	set Finalpath to {pdfsgohere & x, "-" & y, "-" & z & " " & docname} as string
	save current document in Finalpath as pdf ¬
		with options {class:PDF save options ¬
		, compatibility:Acrobat 6 ¬
		, acrobat layers:true ¬
		, preserve editability:false ¬
		, color compression:automatic JPEG low ¬
		, compress art:true ¬
		, optimization:true ¬
		, page info:true ¬
		, registration marks:true}
end tell
display dialog Finalpath

PreTech

Illustrator CS has a bug that will cause file saving with scripts to fail, especially when saving EPS files. One workaround is to create an empty placeholder file first then have Illustrator save into it. I’ve been using this code as a save subroutine:


on EPSfileSave(savePath, newFileName)
	set fileName to (savePath as string) & newFileName & ".eps"
	try
		open for access file fileName -- will create file if it doesn't exist
		close access file fileName -- then close it
	end try
	tell application "Illustrator CS"
		save document 1 in file fileName as eps with options {compatibility:Illustrator 10, CMYK PostScript:true, embed linked files:true, PostScript:level 2, preview:color Macintosh}
	end tell
end EPSfileSave

Not certain is this applies to saving out as PDF, but it could be possible. Thankfully this was fixed in CS2.
:slight_smile:

Thanks Pretech/mLeslie

Pretech had already tried that in between posts and it still didn’t work, still got a load of junk on the end of my file,
if your interested this is the name of one of the many files i want to convert: “62254_1500x150_TODD_ACC_BLINK.ai”
Sometimes the file names are even several more characters longer than this aswell, my script just ignores these altogether.

mleslie placed in your subroutine (the best i could still learning!) got it to work. when i run the script it still adds the junk,
e.g. “62254_1500x150_TODD_AC#BBBF6.ai.pdf” but what it does do is it doesn’t ignore the even longer file names anymore it does process and create pdf’s
which is a step forward.

cheers guys for your help
appreciate it…

Pidge1,

This sounds somewhat similar to a problem I had with a StuffIt Deluxe script. If the name was longer than 27 characters, the script would error. I worked around this by saving the file to an “untitled” name and then selecting that file and renamed it. That might be an approach.

PreTech

Hi Pretech

Yep! i think your right, i’m thought i might have to go down that route,
not entirely sure how i would go about passing so many files names from one to another,
have you got any tips?

cheers

If anyone is interested!
This definitely a CS1 bug just tested my script on illustrator CS2 and it worked just fine, Doesn’t effect the file name at all…
Time for an upgrade me thinks…

cheers for all your help…

Pidge1,

I’ve played around with this today and it seems to have something to do with when the name is brought from Illustrator to the Finder. If you display a dialog that has the doc name in it from Ill, it shows the correct name. Even when I tried to rename the file after it is created (using docname) it ends up with the extra characters. Maybe you could get the name of the original file and then add the date info and replace the name from within the Finder. I’ll play some more. Out of time today.

PreTech

Pidge1,

Sorry, but I lied. The file name is messed up in Ill CS when you display it. But I did come up with a way around I believe. This script is not quite like yours. I kind of started from scratch, but you should be able to put the pieces in their place.

set fileType to ".ai"

set d to day of (current date)
set m to month of (current date) as number
set y to year of (current date) as number
set theDate to (day of (current date) & "-" & (month of (current date) as number) & "-" & year of (current date)) as string
set theItems to choose file with multiple selections allowed
set pdfDestination to choose folder with prompt "Pick where you want these pdf's to go."
set theDest to pdfDestination as string
set fileName to theDate & " untitled.pdf" as string
tell application "Finder"
	activate
	repeat with anItem in theItems
		if class of anItem is folder then
			set folderContents to every item of anItem
			open folderContents
		else
			set itemExtension to "." & (name extension of anItem)
			if fileType is itemExtension then
				set theFileName to name of anItem
				set fullName to theDate & theFileName & ".pdf"
				tell application "Illustrator CS"
					activate
					open anItem
					set docname to name of current document
					display dialog docname
					--do script "Delete Unused Palette Items" from "Default Actions" without dialogs
					set Finalpath to theDest & fileName
					display dialog Finalpath
					save current document in Finalpath as pdf with options {class:PDF save options, compatibility:Acrobat 6, acrobat layers:true, preserve editability:false, color compression:automatic JPEG low, compress art:true, optimization:true, page info:true, registration marks:true}
				end tell
			end if
		end if
		set theFile to file (theDate & " untitled.pdf") of pdfDestination
		reveal theFile
		tell application "Finder" to set name of theFile to fullName
	end repeat
end tell

Hope this does the trick.

PreTech

Pretech

Yep thats bang on!
I will jig it about abit to suit my needs but thats perfect,
Still gunna work on the bosses to upgrade to CS2,
but thats a fantastic work round…

Cheers
pidge1