Help getting file info into Illustrator files

I need to process a directory of mixed format files, choose only the .ai & .eps files, place some file info on the page and print, then close without saving, while repeating with all Illustrator files only. I know this is dirty, but I am learning Applescript out of necessity and in a rush. I am trying to stick to the tutorials, but sometimes my needs outweigh my abilities. If anyone can maybe point out the areas that need cleaning, I would appreciate it greatly.

Here we go, hold on!


on run
	set FileSample to choose file
	--repeat with all files in folder FileSample
	tell application "Finder"
		--set to only process .eps & .ai files
		open FileSample
	end tell
	set InfoF to (info for FileSample)
	--set InfoS to (do shell script "mdls " & quoted form of POSIX path of FileSample)
	
	set myList to {item 1 of FileSample, item 2 of FileSample, item 3 of FileSample, item 4 of FileSample} as string
	
	tell application "Finder" to get POSIX path of ((FileSample) as alias) as string
	
	--set creationDate to creation date of InfoF
	--set modDate to modification date of InfoF
	--set fileLocation to POSIX path of FileSample --Good
	--set fileName to name of document 1 of application "Adobe Illustrator"
	
	
	--get creation date of FileSample as list
	--get modification date of FileSample as list
	--get item 1 of file FileSample as list
	
	--Set fileSampleInfo to fileName + folderName + createDate + modDate
	
	set myString to " "
	repeat with anItem in myList
		set myString to myString & anItem & " "
	end repeat
	myString
	
	--Second, import the file info into the file as text into a text box.
	
	tell application "Adobe Illustrator"
		activate
		tell front document
			--		set current view to fit
			
			make text frame with properties {contents:{"item 1 of myList, item 2 of myList, item 3 of myList, item 4 of myList"}, kind:point text, position:{50, 740}, name:"Temp Info 1"} --Points are default. Delete quotes around contents!
			print current document
		end tell
	end tell
	close saving no
	--	end repeat
end run

thanks,
Levon

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)

Hi Levon,

Illustrator isn’t actually the first choice to print out just text, but anyway.

try this, I hope, it gathers all the data you need

set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai"}
set myList to {}
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
	set fileLocation to POSIX path of (oneFile as alias)
	set end of myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set myList to myList as text
set text item delimiters to TID

tell application "Adobe Illustrator"
	activate
	make new document
	tell front document
		make new text frame with properties {contents:myList, kind:point text, position:{50, 740}, name:"Temp Info 1"} --Points are default. Delete quotes around contents!
		print
		close saving no
	end tell
end tell

Stefan,
This is almost exactly what I am after. I should have gone into a bit more detail about the purpose of the script. I have a large group of Illustrator files that have art. The art needs to have file info in hardcopy form to be passed along. I made one note to open the art file so that the file info gets placed right above the art. Does this look like it should work? I get all the info for all the files in one document… Thank you so much for your help!


set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai"}
set myList to {}
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
	set fileLocation to POSIX path of (oneFile as alias)
	set end of myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set myList to myList as text
set text item delimiters to TID

tell application "Adobe Illustrator"
   activate
   make new document --Should this be "open oneFile" to place individual file info on each art file page?
   tell front document
		make new text frame with properties {contents:myList, kind:point text, position:{50, 740}, name:"Temp Info 1"} --Points are default. Delete quotes around contents!
		print
		close saving no
	end tell
end tell

thanks,
Levon

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)

I’m sorry for not being very familiar with Illustrator

Hi Sprale

I think this is what you mean! you want the info placed on the same file where the info came from.


set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai"}
set myList to {}
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
	set fileLocation to POSIX path of (oneFile as alias)
	set myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
	
	set {TID, text item delimiters} to {text item delimiters, return}
	set myList to myList as text
	set text item delimiters to TID
	
	tell application "Illustrator CS"
		activate
		open oneFile --Should this be "open oneFile" to place individual file info on each art file page?
		tell document 1
			make new text frame with properties {contents:myList, kind:point text, position:{50, 740}, name:"Temp Info 1"} --Points are default. Delete quotes around contents!
			--print -- Does save needs to go here? instead of print
		end tell
		save current document as eps with options {class:EPS save options, compatibility:Illustrator 8} --this will overwrite files with same names
		close current document saving no
	end tell
end repeat

apologies if i’m wrong!
when you just “print” you get an illustrator text file, this errors when you have art and text cause by definition you can only store text in a text file (i think!)
so you need to save. i must add that this is a very basic save! you could do with changing it slightly renaming or adding something else to the end of the original named file,
just do a search on here for help with that or have a try yourself. post back if you really struggle but you seem to be doing quite well at the moment!

Pidge,
I can not get CS2 to process any of the files in the list. I need the script to get info for a file in the list, add the info to the Illustrator file, the go to the next file in the list. It chooses the proper folder, but I can not tell if it gets the info correctly. It does not continue on to open the file in Illustrator, nor does it place the info, print and close. Is this maybe a difference between CS & CS2? My brain is full for the day… I think I will restart and continue in the morning. Thanks for all the help and advice.


set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai"}
set myList to {}
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
	set fileLocation to POSIX path of (oneFile as alias)
	set end of myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
end repeat
set {TID, text item delimiters} to {text item delimiters, return}
set myList to myList as text
set text item delimiters to TID

tell application "Adobe Illustrator"
	activate
	open oneFile
	tell front document
		make new text frame with properties {contents:myList, kind:point text, position:{50, 740}, name:"Temp Info 1"}
		print
		close saving no
	end tell
end tell

--This script works very well on one file, but ignores files without extensions... It inserts all the info from all files into the first in the list

The previous version of the script from Stefan, above, processes one file correctly, but multiple files creates the info all in the first file in the list… I have tried to rearrange the repeat block without luck. Any ideas?

cheers,
Levon

p.s. I am listening to the Radio 1 show from Ibiza, it is wonderful!


tell application "Brain"
restart
end tell

:slight_smile:

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)

Hi }

Not sure what you pointing to exactly by this!!

The script i posted worked fine in CS2,
However i’m starting to wonder if this is what your after??

I don’t think you need to be going down the route of printing the information from the file, on my machine it just doesn’t like it and you get odd results.
Besides printing in illustrator from a scripting point of view can be a bit temperamental to say the least.
And needs a lot more parameters other than just “print” to be of any more use than maybe just the one file that your getting!!

can you give us a bit more info about the end file?
like what format it wants to be in {eps, ai, pdf, etc.}
does the info want to be added to the artwork file?
are you just wanting to add the info print off the document then close not saving??
if your adamant about going down the print route are you printing to a postscript file or a pdf or a printer etc.
More info needed please and i’m sure we can get this sorted and you can get back to chilling in front of the radio.

good luck!

in the meantime try this but change a few things to your printer info!


set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai"}
set myList to {}
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
	set fileLocation to POSIX path of (oneFile as alias)
	set myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
	
	set {TID, text item delimiters} to {text item delimiters, return}
	set myList to myList as text
	set text item delimiters to TID
	try
		set the_ppd to "magicolor_2350" -- put exact name of your ppd here
		do shell script "lpoptions -d" & the_ppd
	end try
	tell application "Adobe Illustrator"
		activate
		open oneFile --Should this be "open oneFile" to place individual file info on each art file page?
		tell document 1
			make new text frame with properties {contents:myList, kind:point text, position:{0, 100}, name:"Temp Info 1"}
			delay 0.5
		end tell
		set printOpts to {class:print options, print preset:"Magicolor 2350" as Unicode text}
		print current document options printOpts --without dialogs
		close current document saving no
	end tell
end repeat

you will need to make sure your ppd name in the shell script above is correct including underscores and also the name in the printopts bit as well.

to get the ppd name correctly type this into your terminal “lpstat -t” you shpuld pick the info up from there.
any probs post back.

Maybe this works for you, I added some conditions to get files also without an extension

set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai"} or kind contains "Postscript" or kind contains "EPS" or kind contains "Illustrator"
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
	set fileLocation to POSIX path of (oneFile as alias)
	set myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
	tell application "Adobe Illustrator"
		activate
		open (oneFile as alias)
		tell front document
			make new text frame with properties {contents:myList, kind:point text, position:{50, 740}, name:"Temp Info 1"}
			print
			close saving no
		end tell
	end tell
end repeat

Thanks for all the help Pidge & Stefan! I added a little bit here and there to compensate for some old files with legacy text that were in the mix. I changed the printer to default, since the script will be used by many users with different printers. I added the set origin command, because some files have random origins. I also added a bit in to deal with the odd file naming conventions, why anyone would use a .ART1 after a file name confounds me. I could not have come this close in less than 10 pages of code to having this script work. Thanks for all the guidance and advice. I am looking forward to learning more Applescript, but hopefully I will not have to do it in such a rush again any time soon!

Here is the final version that you both helped me with so much. Maybe it can help out more scripters in time as well.


set FileSample to choose folder
set folderName to name of (info for FileSample)
tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai", "ART1", "ART2", "ART3", "ART4"} or kind contains "Postscript" or kind contains "EPS" or kind contains "Illustrator"
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
	set fileLocation to POSIX path of (oneFile as alias)
	set myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
	tell application "Adobe Illustrator"
		activate
		open (oneFile as alias) with options {update legacy text:true} forcing CMYK without dialogs
		tell front document
			set ruler origin to {0.0, 0.0}
			make new text frame with properties {contents:myList, kind:point text, position:{50, 740}, name:"Temp Info 1"}
			print
			close saving no
		end tell
	end tell
end repeat

thanks again and cheers!
Levon

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)

I have been able to successfully save this as an app, but am having trouble now when changing to select a file. When I try to change the choose folder to choose file, I get the following error.


on run
	
	--	set FileSample to (choose folder) --use this one instead if you want to process an entire folder
	set FileSample to choose file with prompt "Select multiple files with the Command (Apple) key." with multiple selections allowed without invisibles

	set folderName to name of (info for FileSample) --only necessary if needed for myList
	
	tell application "Finder" to set theFiles to files of folder FileSample whose name extension is in {"eps", "ai", "ART1", "ART2", "ART3", "ART4"} or kind contains "Postscript" or kind contains "EPS" or kind contains "Illustrator" or kind contains "ART5"
	
	repeat with oneFile in theFiles
		set {creation date:creationDate, modification date:modDate, name:Filename} to info for oneFile as alias
		set fileLocation to POSIX path of (oneFile as alias)
		
		set myList to "Filename: " & Filename & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
		--		set myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return --Use this set to input the Parent folder line.
		
		tell application "Adobe Illustrator"
			activate
			open (oneFile as alias) with options {update legacy text:true} forcing CMYK without dialogs --Will not display font errors
			--Set view to fit page
			tell front document
				set ruler origin to {0.0, 0.0}
				make new text frame with properties {contents:myList, kind:point text, position:{25, 770}, name:"Temp Info 1"}
				--set size of text frame "Temp Info 1" to 9
				print
				close saving no
			end tell
		end tell
	end repeat
end run

thanks,
Levon

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)

then you should change to script to something like this

--	set FileSample to (choose folder) --use this one instead if you want to process an entire folder
set theFiles to choose file with prompt "Select multiple files with the Command (Apple) key." with multiple selections allowed without invisibles
repeat with oneFile in theFiles
	set {creation date:creationDate, modification date:modDate, name:Filename, name extension:Ex, kind:fileKind} to info for oneFile as alias
	if Ex is in {"eps", "ai", "ART1", "ART2", "ART3", "ART4"} or fileKind contains "Postscript" or fileKind contains "EPS" or fileKind contains "Illustrator" or fileKind contains "ART5" then
		set fileLocation to POSIX path of (oneFile as alias)
		
		set myList to "Filename: " & Filename & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return
		--		set myList to "Filename: " & Filename & return & "Parent folder: " & folderName & return & "Creation date: " & (creationDate as string) & return & "Modification date: " & (modDate as string) & return & "Location: " & fileLocation & return & return --Use this set to input the Parent folder line.
		
		tell application "Adobe Illustrator"
			activate
			open (oneFile as alias) with options {update legacy text:true} forcing CMYK without dialogs --Will not display font errors
			--Set view to fit page
			tell front document
				set ruler origin to {0.0, 0.0}
				make new text frame with properties {contents:myList, kind:point text, position:{25, 770}, name:"Temp Info 1"}
				--set size of text frame "Temp Info 1" to 9
				print
				close saving no
			end tell
		end tell
	end if
end repeat

Thanks Stefan! I am comparing the last version to the one you just modified and I am following that you made the extension or filetype into a variable also. That makes sense to me now that I have run it a few times. Little by little it gets easier for me to understand, thanks to the gracious help and advice here in the forums.

thanks,
Levon

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/SD4
Browser: Firefox 2.0.0.4
Operating System: Mac OS X (10.4)