Removing items from list

My script:

  1. prompt a user for a folder of files they want processed.
  2. compile list of files in folders and subfolders that end in “ai”
  3. open files in list and process -save, close –

tell application "Finder"
	activate
	set the source_folder to (choose folder with prompt "Process all Illustrator files in what folder?")
	
	set allFiles to entire contents of source_folder
	
	set myfilelist to allFiles whose name extension is "ai"
	
	set DocCount to count every item of myfilelist
	
	tell application "Adobe Illustrator"
		activate
		set user interaction level to never interact
		delay 1
		open myfilelist without dialogs
		repeat with i from 1 to DocCount
			save current document as Illustrator with options {PDF compatible:true, embed ICC profile:false}
			
			close current document saving no
		end repeat
	end tell
end tell

The script works without the “whose name extension is”, however that doesn’t do me any good.

Would also like to know how to suppress or continue past and fonts missing dialog box.

Thanks in advance, Char

Model: macBookPro
AppleScript: 2.2.1
Browser: Firefox 3.6.10
Operating System: Mac OS X (10.5)

I believe this is more what you’re looking for. Notice the change in the call to the Finder, it doesn’t surround the rest of your calls, creating your calls that way is actually more correct and will create more stable code. As for the issue with the fonts, I believe that’s what the “user interaction level to never interact” is doing for you.

set the source_folder to (choose folder with prompt "Process all Illustrator files in what folder?")

tell application "Finder" to set myfilelist to every file of source_folder whose name extension is "ai"
tell application "Adobe Illustrator" to set user interaction level to never interact

repeat with aFile in myfilelist
	tell application "Adobe Illustrator"
		open aFile
		save current document as Illustrator with options {PDF compatible:true, embed ICC profile:false}
		close current document saving no
	end tell
end repeat

Thanks Shai1, your code is much cleaner!

However, the script still doesn’t process items in subfolders. Any more ideas?

From Finder’s dictionary:
container‚n [inh. item] : An item that contains other items
.
.
properties
entire contents (specifier, r/o) : the entire contents of the container, including the contents of its children
.
.

Tried that. Doesn’t like the ‘entire contents’ with the ‘whose name extension is’

Hi,

the problem is, that AI cannot process Finder file specifier, you should corece it to alias


.
open (aFile as alias)
.

If your files are indexed by Spotlight there is a smarter way to get the files in all subfolders


property findtype : quoted form of "kMDItemKind = \"Adobe Illustrator document\""

set the source_folder to (choose folder with prompt "Process all Illustrator files in what folder?")
set ai_files to paragraphs of (do shell script "mdfind -onlyin " & quoted form of POSIX path of source_folder & space & findtype)

tell application "Adobe Illustrator" to set user interaction level to never interact
repeat with aFile in ai_files
	set aFileAlias to POSIX file aFile as alias
	tell application "Adobe Illustrator"
		open aFileAlias
		save current document as Illustrator with options {PDF compatible:true, embed ICC profile:false}
		close current document saving no
	end tell
end repeat


Well, StefanK already posted a good answer. But since I just got this done, I’ll post it anyway.

You can also use ‘find’ to recursively scan directories. Here you will get a list of posix paths that you can than convert back to Mac paths (posix file “/…/…”)


set dirPath to POSIX path of (path to desktop)

set fileExtension to "txt" -- change this to ai

set fileList to listFilesWithExtension(dirPath, fileExtension)
--> list of posix paths


on listFilesWithExtension(posixPath, fileExtension)
	local posixPath, fileExtension, cmd, res
	try
		if posixPath = "/" then
			error "Don't run this on your startup disk!" number 1
			-- would take too long anyway and there will probably 
			-- be some permission issues
		else if posixPath = "" then
			error "Invalid directory path!" number 2
		else if posixPath ends with "/" then
			set posixPath to posixPath's text 1 thru -2
		end if
		set posixPath to quoted form of posixPath
		set cmd to "find " & posixPath & " -type f -name \"*." & fileExtension & "\""
		set res to do shell script cmd
		if res ≠ "" then
			set res to paragraphs of res
		else
			set res to {}
		end if
		return res
	on error eMsg number eNum
		error "Can't listFilesWithExtension: " & eMsg number eNum
	end try
end listFilesWithExtension

Regards
Luke

Getting closer!!!


property findtype : quoted form of ".ai"

set the source_folder to (choose folder with prompt "Process all Illustrator files in what folder?")
set ai_files to paragraphs of (do shell script "mdfind -onlyin " & quoted form of POSIX path of source_folder & space & findtype)

tell application "Adobe Illustrator" to set user interaction level to never interact
repeat with aFile in ai_files
	set aFileAlias to POSIX file aFile as alias
	tell application "Adobe Illustrator"
		open aFileAlias
		save current document as Illustrator --with options {compatibility:Illustrator 13, PDF compatible:true, embed ICC profile:false}
		close current document saving no
	end tell
end repeat

This will work once…then I get an error '“Adobe Illustrator got an error: File/Folder expected”

I doubt that this definition of findtype is what you want :wink: