Freehand Scripting for Automation

We have a client that sends 90% of their work in as Freehand files. We are looking for ways to automate a workflow for them but this will require some AS scripting to work with a third party workflow automation software package.

Here are my challenges:

About 20% of the supplied Freehand files are FH9 and need to be converted to FH11. I have a script which does this successfully.

FH11 files need to be exported to EPS. I have a script which will successfully accomplishes this task also, but it contains some unnecessary elements, some apparently redundant steps and produces 1 unwanted result - I need the filename to be 8 characters plus extension but I get 8 characters + .FH11 + .EPS. It also does not do some things that I would like it to do (See below).

As far as the automated workflow is concerned, here is what needs to happen:

A batch of folders containing FH (mix of FH9 and FH11) files is dropped onto a hot folder - FH9 files are identified and converted to FH11. The whole batch is then passed on to the next step where EPS files are exported from all the FH11 files. All these files contain multiple layers with very strict naming conventions. My problem lies in that some may be missing a necessary layer (always named “DC”) and these need to be set aside for some manual intervention. There is also a layer (always name “Do Not Print”) which I need to appear in the EPS, but it is set as non-printing.

The hot folders used for this process will be static, so I would like to hard code original and destination locations into the script. I am an absolute AS newbie and need some help with this one.

Here is the convert to FH11 script.


on open x
	with timeout of 14400 seconds
		tell application "Finder"
			set droppedFiles to count x
			repeat with cnter from 1 to droppedFiles
				set currentfile to item cnter of x
				copy (file type of file currentfile) to crCheck
				if characters 1 thru 3 of crCheck as string is equal to "FHD" then
					beep 1
					display dialog "FreeHand MX cannot open v2 or v3 FreeHand files. " & ¬
						"Please use the FreeHand 8 conversion script " & ¬
						"with FreeHand 8 to convert those file types. " & return & return & ¬
						"" buttons "OK" default button 1
				else
					if characters 1 thru 3 of crCheck as string is equal to "AGD" then
						saveas11files(currentfile) of me
					else
						beep 1
					end if
				end if
			end repeat
		end tell
	end timeout
end open

on saveas11files(currentfile)
	tell application "FreeHand MX"
		open currentfile with Dialogs
		set currentfile to currentfile as string
		set AppleScript's text item delimiters to {":"}
		set currentDir to ((text items 1 through -2 of currentfile) as string) & ":"
		set filename to ((last text item of currentfile) as string)
		if length of (filename as string) is greater than 8 then
			set filename to (text 1 thru 8 of filename) as string
			set newFile to (currentDir & filename) as string
			set currentfile to currentfile as alias
		else
			set newFile to currentfile as alias
			set currentfile to currentfile as alias
		end if
		set AppleScript's text item delimiters to {}
		set fileExtension to {"FH11"}
		set newName to (newFile as string) & "." & fileExtension
		save last document in file newName
		close last document
	end tell
end saveas11files

I don’t need the warning regarding FH 8 files.

Here is the export as EPS script:



on open x
	with timeout of 14400 seconds
		tell application "Finder"
			try
				set originFolder to choose folder with prompt "Where do you want to save your EPS files?"
			on error
				beep
				display dialog ¬
					"You must have Navigation Services installed " & ¬
					"to run this script." buttons {"Cancel"} ¬
					default button "Cancel"
			end try
			set withEPS to true
			set droppedFiles to count x
			repeat with cnter from 1 to droppedFiles
				set currentfile to item cnter of x
				copy (file type of file currentfile) to crCheck
				if characters 1 thru 3 of crCheck as string is equal to "FHD" then
					beep 1
					display dialog "FreeHand MX cannot open v2 or v3 FreeHand files. " & ¬
						"Please use the FreeHand 8 conversion script " & ¬
						"with FreeHand 8 to convert those file types. " & return & return & ¬
						"" buttons "OK" default button 1
				else
					if characters 1 thru 3 of crCheck as string is equal to "AGD" then
						if withEPS then
							exportfh11files2(currentfile, originFolder) of me
						else
							exportfh11files(currentfile, originFolder) of me
						end if
					else
						beep 1
					end if
				end if
			end repeat
		end tell
	end timeout
end open

on exportfh11files(currentfile, originFolder)
	tell application "FreeHand MX"
		open currentfile with Dialogs
		set currentfile to currentfile as string
		set AppleScript's text item delimiters to {":"}
		set currentDir to ((text items 1 through -2 of currentfile) as string) & ":"
		set filename to ((last text item of currentfile) as string)
		if length of (filename as string) is greater than 8 then
			set filename to (text 1 thru 8 of filename) as string
			set newFile to (currentDir & filename) as string
			set currentfile to currentfile as alias
		else
			set newFile to currentfile as alias
			set currentfile to currentfile as alias
		end if
		set EPS_Location to originFolder & currentfile & ".eps" as string
		save last document as MacEPS in file EPS_Location with IncludeFHDocInEPS
		close last document
	end tell
end exportfh11files

on exportfh11files2(currentfile, originFolder)
	tell application "FreeHand MX"
		open currentfile with Dialogs
		set currentfile to currentfile as string
		set AppleScript's text item delimiters to {":"}
		set currentDir to ((text items 1 through -2 of currentfile) as string) & ":"
		set filename to ((last text item of currentfile) as string)
		if length of (filename as string) is greater than 8 then
			set filename to (text 1 thru 8 of filename) as string
			set newFile to (currentDir & filename) as string
			set currentfile to currentfile as alias
		else
			set newFile to currentfile as alias
			set currentfile to currentfile as alias
		end if
		set EPS_Location to originFolder & currentfile & ".eps" as string
		save last document as MacEPS in file EPS_Location with IncludeFHDocInEPS
		close last document
	end tell
end exportfh11files2


I don’t need the warning regarding FH 8 files and all files should contain the FH document in the EPS. I would like to turn all layers to printing layers, send all good files to one static location and bounce any files that do not contain a layer named “DC” to a problem files folder.

Can this be simplified? Done all in one script? Are the steps regarding the layers easily accomplished?

Thanks in Advance,

Lunarlandr

Hi,
There’s quite a lot of things that you want to do and I’m sure if MX’s dictionary allows these functions then it can be scripted. Can you try this small script? It should get around your naming problems and will save an EPS and, I think will include the freehand document. If you get any positive results from this then we can start to build the script to include your other features.

set thefile to choose file
tell application "Finder" to set original_filename to name of thefile
set filepath to thefile as string
set myoffset to offset of original_filename in filepath
set savepath to text 1 thru (myoffset - 1) of filepath
set newname to text 1 thru 8 of original_filename & ".EPS"
tell application "FreeHand MX"
	open thefile
	set OutputOptions document 1 ImageData Binary Flatness 0 with IncludeInvisible and RGBtoProcess --> specify output options here
	save document 1 in file (savepath & newname) as GenericEPS
	close document 1 saving no
end tell

Thanks,
Nik

Hi

Looks like Blend has beaten me to it!!
but here you go anyway for what its worth!!
The dictionary in freehand for want of a better word is “Shit”
the naming and saving stuff you want is fine but the layer stuff is very limited from what i can see!!
my advice to you would be to move to illustrator asap. it will open up a who;e new world of scriptability but thats just me!!
anyhow heres my take on saving as an eps.


to open x
	set originFolder to choose folder with prompt "Where do you want to save your EPS files?"
	repeat with i in x
		tell application "FreeHand MX"
			open i
			--Set LayerInfo Layer "Do Not Print" with Visible and Locked
			tell application "Finder" to set currentfile to name of file i as string
			set OldDelims to AppleScript's AppleScript's text item delimiters
			set AppleScript's AppleScript's text item delimiters to ".FH11"
			set newText to text items of currentfile
			set AppleScript's AppleScript's text item delimiters to ""
			set newText to newText as text
			set AppleScript's AppleScript's text item delimiters to OldDelims
			set EPS_Location to originFolder & newText & ".eps" as string
			save last document as MacEPS in file EPS_Location with IncludeFHDocInEPS
			close last document
		end tell
	end repeat
end open

just out of interest i came across these 2 sites: http://www.peachpit.com/content/images/0201353598/samplechapter/chapter03.html
http://www.freehandsource.com/_frames/_tips/_scripting/scripting_faq01.html

good luck!

Guys,

Thanks for the replies! Both of your solutions are wonderful as far as the naming convention goes, but no matter what I try I can’t get the invisible layers set to on in the EPS. What’s really strange is that in Pidge’ s solution in the “set outputOptions” command the word “set” appears bold in his post (as it should be), but when I paste in my editor and compile, it is normal - like it is not being seen as a command. What’s up with that?

Any other ideas? Besides going to Illustrator - sounds wonderful but this client has a library of about 40,000 to 50,000 documents all done in FH, so I’m stuck.

Lunarlandr

Hi,
“set OutputOptions” shouldn’t appear bold in your script, I think the reason it’s displaying like that is down to the Applescript Syntax button on this site! I was hoping that “IncludeInvisible” was going to activate that layer but maybe it just Includes it in the EPS without actually making it visible/active? It does look like it can be done though, the Dictionary for mx reads:

Unfortunately I don’t have any files like you describe, maybe you could email me an example and I’ll have a go at making the layer visible?
Nik

Hi,
on further investigation it appears that you need to know the layer number rather than name to turn its visibility on or off, do you know the layer number? Can you try this? If I have a document with 3 layers it will turn the layer visibility on or off!

tell application "FreeHand MX"
	--Set LayerInfo Layer 3 without Visible
	Set LayerInfo Layer 3 with Visible
	Update
end tell

Thanks,
Nik

Hi

i managed to get the layer visible by using its name.

Set LayerInfo Layer "Do Not Print" with Visible

checkout my early post the bit thats commented out!! if you name it exactly as it is in the layer then it works!

is the issue that the non printing layer is non printing due to its visability or is it set under the line in the layer pallette that makes it non printing!
cause if its just a visibility thing then it can be done easily if its not then its harder if not impossible!!

i guess you can also use the layer number as Nik mentions!!

To All,

Thanks for the help! the naming convention issue is resolved and now I can script layers to be visible/invisible at will. As it turns out, I’ve just been chasing my tail. After searching the internet far and wide for clues, I found an article which presented the idea of using the FH document report to check your scripting. It turns out that visible and invisible is not the issue after all, rather foreground or background - I need to move layers from background to foreground. No reference of any sort in the scripting dictionary. Am I just out of luck on this one, or can I script the UI in some way?

Lunarlandr

Hi

Your right about the dictionary its very sparce, which cuts down your options fast!
I don’t think theres any keyboard shortcuts for layers on your GUI scripting idea!!
so scripting the interface as far as i can see is out!!

i know i mentioned this earlier and you kinda dimissed it but do you have illustrator?, cause you can export out of
freehand as an illustrator file (I think) in your script and continue editing your files in illustrator then save them down as an eps.

layers are a lot more scriptable once your in illustrator and you shouldn’t have a problem doing what you want!!
I know i keep pluggin Illustrator (don’t worry i don’t work for adobe!!:wink: ) but if you convert your files your workflow will come on leaps and bounds!!

Just a thought!!
Hope this helps!!