Quark to Postscript help w/existing code PLEASE!

I have this code that works perfectly on an individual basis. What I want is to hit “run” and for the script to ask me to choose a folder and then it would perform the action described in the rest of the script. That way I don’t have to manually select each of 500 files manually as the previous one finishes. Is it possible?

set this_item to (choose file)
tell application “QuarkXPress”
open this_item use doc prefs yes remap fonts no do auto picture import yes
–open this_item use doc prefs yes remap fonts ask do auto picture import yes
delay 11
tell document 1
set DocName to the name
end tell
tell print setup of document 1
set printer type to “AdobePDF 8.0”
set paper size to “Custom”
set paper width to “7.937”
set orientation to portrait
set page position to center horizontal
set print spreads to false
set reduce or enlarge to “100%”
end tell
tell document DocName
set fp to “Macintosh HD:Users:Ivietx2250:Desktop:POSTSCRIPT FILES:”
set fileName to fp & DocName & “.ps” as string
–set printfilename to myFolder & fileName --myFolder is a pre-defined destination alias as a global variable
print PostScript file fileName
–display dialog “success”
end tell
close document DocName saving no
end tell

Thanks for anyone’s help

Browser: Safari 523.12
Operating System: Mac OS X (10.4)

Hello! Welcome to the forums.

If you really want to process all the files in a folder, you can do it like this:

set theFolder to choose folder
try
	tell application "Finder" to set allItems to files of theFolder as alias list
on error m number n from o partial result r to t
	using terms from application "Finder"
		set aliasListClass to alias list
	end using terms from
	if n is -1700 and t is aliasListClass then
		tell application "Finder" to set allItems to {(first file of theFolder) as alias}
	else
		error m number n from o partial result r to t
	end if
end try
repeat with this_item in allItems
	set this_item to contents of this_item -- dereference the implicit reference
	-- Process this_item
end repeat

The first part is a bit verbose due to having to work around a bug with Finder (I hear that it is fixed in 10.5). But the idea is simple enough: use Finder to gather a list of files in your chosen folder (files of theFolder) and then run a loop over that list. Pretty much you just stick your code where the comment “-- Process this_item” is now.

If you would like to be able to select which files you want to process each time (you can always use ⌘A (Command-A) to select all the files in the active folder if you really want to process all of them), you can do this instead:

set allFiles to choose file with multiple selections allowed without invisibles
repeat with this_item in allFiles
	set this_item to contents of this_item
	-- Process this_item
end repeat

That way if you find that you need to reprocess some (but not all) of the files, you can just select the ones you want. With the previous version you would have to move the ones that were already done out of the source folder first (so they were not reprocessed). Also, choose file has an of type argument that you could probably use to limit the selectable files to just Quark documents, for example. Check the dictionary (Script Editor File > Open Dictionary.) of the Standard Additions OSAX for more info on choose file.

Hi

Just to add to what Chrys is saying you can also use “entire contents” and then filter it down to the file types you want (i.e. “quark files”)

tell application "Finder" to set t to files of entire contents of (choose folder) whose file type is "XPRJ" --quark file type

Thanks for your help guys! I ended up combining my script with another I found on here to create an applet that works great. Although there is a dialog box that pops up that let’s me know that this document was created with an xtension that is no longer available and it may be reflowed. In system 9 I could use “Okey Dokey” to auto push ok for me but it’s not compatible with os x. Is there another similar application or is there a way to add to something to my code to push ok for me?

– This droplet processes both files or folders of files dropped onto the applet
on open these_items

set The_Path to choose folder with prompt "Please select the Distiller In folder."

repeat with i from 1 to the count of these_items
	set this_item to (item i of these_items)
	set the item_info to info for this_item
	
	if folder of the item_info is true then
		process_folder(this_item, The_Path)
	else if (alias of the item_info is false) then
		my process_item(this_item, The_Path)
	end if
end repeat

end open

– this sub-routine processes folders
on process_folder(this_folder, The_Path)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as text) & (item i of these_items))
set the item_info to info for this_item
if folder of the item_info is true then
process_folder(this_item, The_Path)
else if (alias of the item_info is false) then
my process_item(this_item, The_Path)
end if
end repeat
end process_folder

– this sub-routine prints the files
on process_item(this_item, The_Path)
tell application “QuarkXPress”
open this_item use doc prefs yes remap fonts no do auto picture import yes
–open this_item use doc prefs yes remap fonts ask do auto picture import yes
delay 11
tell document 1
set DocName to the name
end tell
tell print setup of document 1
set printer type to “AdobePDF 8.0”
set paper size to “Custom”
set paper width to “7.937”
set orientation to portrait
set page position to center horizontal
set print spreads to false
set reduce or enlarge to “100%”
end tell
tell document DocName
set fp to “Macintosh HD:Users:Ivietx2250:Desktop:POSTSCRIPT FILES:In:”
set fileName to fp & DocName & “.ps” as string
–set printfilename to myFolder & fileName --myFolder is a pre-defined destination alias as a global variable
print PostScript file fileName
–display dialog “success”
end tell
close document DocName saving no
end tell
end process_item

Thanks for any help you can provide.

Actually, I was able to find a keystroke command that worked perfectly. Here is the script for the applet I’m using in case anyone else needs it along the way.
Thanks for your posts and the help.


-- This droplet processes both files or folders of files dropped onto the applet 
on open these_items
	
	
	set The_Path to choose folder with prompt "Please select the Distiller In folder."
	
	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		set the item_info to info for this_item
		
		if folder of the item_info is true then
			process_folder(this_item, The_Path)
		else if (alias of the item_info is false) then
			my process_item(this_item, The_Path)
		end if
	end repeat
end open

-- this sub-routine processes folders 
on process_folder(this_folder, The_Path)
	set these_items to list folder this_folder without invisibles
	repeat with i from 1 to the count of these_items
		set this_item to alias ((this_folder as text) & (item i of these_items))
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item, The_Path)
		else if (alias of the item_info is false) then
			my process_item(this_item, The_Path)
		end if
	end repeat
end process_folder

-- this sub-routine prints the files 
on process_item(this_item, The_Path)
	tell application "QuarkXPress"
		open this_item use doc prefs yes remap fonts no do auto picture import yes
		--open this_item use doc prefs yes remap fonts ask do auto picture import yes
		tell application "System Events"
			keystroke "." using {command down}
		end tell
		delay 11
		tell document 1
			set DocName to the name
		end tell
		tell print setup of document 1
			set printer type to "AdobePDF 8.0"
			set paper size to "Custom"
			set paper width to "7.937"
			set orientation to portrait
			set page position to center horizontal
			set print spreads to false
			set reduce or enlarge to "100%"
		end tell
		tell document DocName
			set fp to "Macintosh HD:Users:Ivietx2250:Desktop:POSTSCRIPT FILES:In:"
			set fileName to fp & DocName & ".ps" as string
			--set printfilename to myFolder & fileName --myFolder is a pre-defined destination alias as a global variable
			print PostScript file fileName
			--display dialog "success"
		end tell
		close document DocName saving no
	end tell
end process_item