Freehand Open Document without Dialogs

I have an automated workflow which downloads zip files from FTP, unzips them, archives them, sorts them, and is supposed to open any Freehand files - suppressing any dialogs - and save them out as EPS files. My problem is that I can’t seem to get the dialogs to suppress. Any takers? BTW - this is a script which runs inside a workflow automation package called Power Switch, so that is the reason for any strange looking code. When a Dialog pops up Power Switch shows Freehand receiving a type 3 error. Could we possibly build in an error handler to close that particular file and direct it to a different location?

-- ==================================================================================================
-- This is an example Applescript showing how to open a file in Freehand and save it back out as an
-- EPS file
--
-- ----------------------------------------------------------------
-- Author: David van Driessche, Gradual Software
-- Last changed: December 19, 2007
-- Copyright: (c) 2007, Gradual Software
-- ==================================================================================================

-- --------------------------------------------------------------------------------------------------
-- jobArrived
-- 
-- Script entry point that is called for each new job that enters the input folder for this script
-- --------------------------------------------------------------------------------------------------
on jobarrived( s, j )

  -- Get the properties of the job we need to process it
	tell application "Current_SWITCH_Server"

		-- Get the path to the job and information about that path
		set theJobPath to path of j
		tell application "Finder"
			set theJobInfo to (info for file theJobPath)	
		end tell

	end tell

	-- Is this is a file or a folder?
	if folder of theJobInfo is true then

		-- This is a job folder. Find all Freehand files in the folder and process them to
		-- EPS. Send all generated EPS files along the flow using the original job (so they'll
		-- all be linked to the incoming job folder.

		-- Begin by creating a folder object and asking it for all its files
		tell application "Finder"

			set theJobFolder to folder theJobPath
			set theFiles to (files of theJobFolder)
			repeat with theFile in theFiles
				
				-- get the extension of this file in upperercase
				set theExtension to my changeCase( (name extension of theFile), "upper")
		
				-- if the extension is "FH11", we're interested
				if (theExtension is equal to "FH11") or (theExtension is equal to "FH") then

					-- get the name of this Freehand file
					set theName to name of theFile
					set newName to (text 2 thru 8 of theName) & text 1 of theName

  						-- Create a temporary file to save the job to
						tell application "Current_SWITCH_Server"
							set theTempFilePath to create path j name newName & ".eps" 
						end tell

						-- Tell Freehand to open the job and save it as EPS
						tell application "FreeHand MX"
							open theFile Dialogs (false)
							save document 1 in file theTempFilePath as MacEPS with IncludeHFDocInEPS
							close document 1 saving no
						end tell

						-- Done processing, send the resulting file to our single output connection
						tell application	"Current_SWITCH_Server"	
							send to single j path theTempFilePath
						end tell

				end if
				
			end repeat

		end tell

	else

		-- This is a single Freehand file. Simply ask Freehand to convert it to EPS on a 
		-- temporary location and then send the resulting EPS file along

  		-- Create a temporary file to save the job to
		tell application "Current_SWITCH_Server"

			-- A temporary path to save the job to
			set theTempFilePath to create path j extension ".eps" 

		end tell

		-- Tell Freehand to open the job and save it as EPS
		tell application "FreeHand MX"

			-- activate
			open alias theJobPath Dialogs false
			save document 1 in file theTempFilePath as MacEPS with IncludeHFDocInEPS
			close document 1 saving no

		end tell

		-- Done processing, send the resulting file to our single output connection
		tell application	"Current_SWITCH_Server"	

			send to single j path theTempFilePath

		end tell

	end if

end jobarrived



on changeCase( this_text, this_case )
	if this_case is "lower" then
		set the comparison_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		set the source_string to "abcdefghijklmnopqrstuvwxyz"
	else
		set the comparison_string to "abcdefghijklmnopqrstuvwxyz"
		set the source_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	end if
	set the new_text to ""
	repeat with thisChar in this_text
		set x to the offset of thisChar in the comparison_string
		if x is not 0 then
			set the new_text to (the new_text & character x of the source_string) as string
		else
			set the new_text to (the new_text & thisChar) as string
		end if
	end repeat
	return the new_text
end change_case_of

Thanks,

Lunarlandr

Hi,
It’s easy enough to prevent the dialogs when opening a file, the problem comes when trying to check for errors. If you suppress the dialogs then you can open any file no matter what’s missing but once it’s open then you need to be able to check for missing fonts/images but I can’t find anything in Freehand’s dictionary that allows you to check a fonts status. Here’s the code for opening without dialogs:

set thefile to choose file

tell application "FreeHand MX"
	open thefile without Dialogs
end tell

Thanks,
Nik

Hi again,
this problem has been bugging me, because we can’t check the font/image status within Freehand I tried to think of another way of checking if fonts/image are missing and this is what I’ve come up with! Instead of suppressing the dialogs we could incorporate a timeout within your script. When Freehand tries to open a document that has fonts/images missing the open command doesn’t complete until you respond to the dialog window, so we can use this to test if there’s a problem. If Freehand doesn’t open the file within a specified time then we can assume that a dialog must be present alerting to missing fonts/images, so we force quit Freehand to get rid of the dialogs and move the file to an error folder!

set thefile to choose file
set myfullpath to "Macintosh HD:untitled folder:"
set file_name to "mynewfile.eps"
set error_Folder to (path to desktop as string) & "Error_Folder"
try
	with timeout of 10 seconds
		tell application "FreeHand MX"
			activate
			open thefile
			--save document 1 in file (myfullpath & file_name) as GenericEPS
			--close document 1 saving no
		end tell
	end timeout
on error
	do shell script "kill_pid=`ps ax | grep 'FreeHand MX.app' | grep -v grep | awk '{ print $1 }'`; kill $kill_pid"
	tell application "Finder" to move thefile to folder error_Folder
end try

You may need to play about with the timeout settings to get a tolerable time for opening documents.
I hope this helps? Please let me know how you get on.
Thanks,
Nik

Nik,

Your suggestion worked like a charm. All files went through the workflow and only the files without error dialogs were processed.

Thanks for your help.

lunarlandr