Batch convert to PDF

Anyone got any idea how to convert a batch of Appleworks files to PDF?

My actual task is this:

  1. Create a mail merge in Appleworks (easy - done this)
  2. Save merged files as individual documents (easy - done this)
  3. Automatically convert the individual documents to PDF
  4. Name the files according to data in a merge field in the document (e.g. name field)
  5. Distribute individually by email

I tried to “record” the process of opening an Appleworks (6.2.2 under OS 10.3.9) file, and saving to PDF (via the print dialog box), but nothing happened.

Quite likley someone has already solved this problem, but after days of searching I haven’t found the solution.

I’m a newbie at Applescript - sum total of my efforts so far is to print “Hello World” on screen, so I’d be very appreciative of any help you good people could offer.

P.S. I hate to contemplate this, but I could use Microsoft Word instead of Appleworks, but as I detest MS Word, this would have to be a last resort.

Thanks,
George

I’m new to this myself but I think you should be able to do the batch convert portion through a script already included in your OS.

Check out HD>Library>Scripts>Printing Scripts>Convert to PDF.scpt.

I think it’ll do what you need. I’ve seen a number of scripts for renaming batches of files around.

At that point I’d just kind of mesh them together or call them from a main script.

Thanks for the suggestion - I thought it would work, but alas, no. Perhaps I am doing something wrong? I found the Convert to PDF script, saved it as an application (to just drop a file icon onto), but it refuses to work for anything but plain text files (yes, it did convert text files - no problem). However, Appleworks files, Word docs, etc., just did nothing. Are these applications (i.e. the ones that created the Appleworks, Word, etc., files not scriptable, and does that make any difference in this case?).

I will keep hunting for a solution, but if you have any further suggestions I’d be delighted to hear them.

George

Just found your msg on a search. I’m trying to do pretty much the same thing. I have a large number of Appleworks 6 files (pages of a book, actually) and I need to PDF them for printing (the thought of manually PDFing each page does NOT appeal to me). I’ve started writing a script that will step through the files in a folder, making a PDF of each. Right off the bat I hit an error. Here’s my script so far:

set folderPath to getFolder()

set fileList to (list folder folderPath) -- sets the path of the folder we're processing

repeat with theFileNo from 1 to (the number of items in fileList)
	-- repeat loop steps through each file in the folder
	
	set workingFile to folderPath & ":" & (item theFileNo of fileList) -- concatenate the file onto the path
	
	if workingFile contains ".cwk" then -- eliminates hidden files - I was having a problem with it trying to open ".DS-Store"
		
		tell application "AppleWorks 6"
			open workingFile
			-- print to a PDF
			close workingFile
		end tell
		
	end if
	
end repeat



-- Eventually this function will display a dialog to choose the folder.
-- For now, though, the folder path is hard coded in it.
on getFolder()
	return "Production HD:Users:mconrad:Desktop:appleworks"
end getFolder

When I run the script, Appleworks displays an error dialog “An unexpected error occurred. #-1700” and this line is displayed in a dialog and in Event Log: “AppleWorks 6 got an error: Can’t make some data into the expected type.”

If I hard code the file path and filename in place of the variable workingFile in the open statement, the scrip executes without an error (except only one file gets opened, of course). I must have a typo somewhere but I’m damned if I can find it.

While I have everybody’s attention – is there a way to display a “choose folder” dialog so I don’t have to hard-code the file path?

Moving to OS X forum.

set folderPath to (choose folder with prompt "Choose the AppleWorks folder:") as string

As far as the PDF part, I don’t know scripting AppleWorks, but if you could script batch printing to a postscript (.ps) file, you could have it print to a Distiller hot folder, which would rip your PDFs. I am assuming you have Distiller of course…

Model: G5 Tower (not Intel) - Script Editor ver 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

scrucurator,

I can help with this so far.

set folderPath to (choose folder with prompt "Choose your folder for processing.") as string
tell application "Finder"
	set fileList to every file of folder folderPath whose name extension is "cwk"
end tell
repeat with theFileNo in fileList
	-- repeat loop steps through each file in the folder
	
	tell application "AppleWorks 6"
		activate
		open theFileNo
		tell application "System Events"
			tell process "AppleWorks 6"
				keystroke "p" using command down
				delay 1
				keystroke return
				tell window "Print"
					click pop up button 3
					click menu item "Adobe PDF" of menu 1 of pop up button 3
					get name of every UI element

				end tell
			end tell

		end tell
		close document 1
	end tell
	
end repeat

This is GUI scripting. However, I can’t seem to get it to select the pdf button to select the print to pdf option. Maybe somebody with better UI scripting skills can straighten it out. Oh, the first “keystroke return” is there for the spread sheet I was using as a test. A dialog pops up if the page is larger than the currently selected printer can handle. You may want to put an if statement around this if you are able to use the UI scripting bit at all. This is the only option I see to save as pdf. I could be wrong :smiley:

PreTech

Thanks for the help!

I had to make a couple small changes to make the script work for me. The two keystroke reuturns are necessary to tell the script to go ahead and print and to OK the filename dialog. And it got confused because my Adobe is named slightly differently than yours.


set folderPath to (choose folder with prompt "Choose your folder for processing.") as string
tell application "Finder"
	set fileList to every file of folder folderPath whose name extension is "cwk"
end tell
repeat with theFileNo in fileList
	-- repeat loop steps through each file in the folder
	
	tell application "AppleWorks 6"
		activate
		open theFileNo
		tell application "System Events"
			tell process "AppleWorks 6"
				keystroke "p" using command down
				delay 1
				tell window "Print"
					click pop up button 3
					click menu item "Adobe PDF 7.0" of menu 1 of pop up button 3
					get name of every UI element
					keystroke return
					keystroke return
					
				end tell
			end tell
			
		end tell
		close document 1
	end tell
	
end repeat

The PDF file for the first document is generated, but after that the script hangs and won’t move on to the next file. Looking at the script I can’t see why. Maybe my Adobe is hanging things up?

Some further investigation revealed that my Adobe PDF printer is having its jobs stopped. I have no clue why.

The best way I’ve found to do this is:
Install CUPS-PDF printer. This makes a printer that spools whatever you print to it to PDF.
http://www.codepoetry.net/projects/cups-pdf-for-mosx
Then, use Automator to create a work-flow to print the selected Finder items to the CUPS printer.
For some reason, using Automator to open and print AppleWorks documents works correctly, but using AppleScript does not… at least not for me.

Hope this helps
G