Pages 09 export as word doc

I’m having a devil of a time finding a solution to this -

Is there a way to make a single script that will export a pages document as Word file?

I’ve gotten to the point where I can click on the menu item for export but when the mini window comes up with the four options of “PDF”, “Word”, “RTF”, and “Plain Text”, I can’t seem to figure out how to get it to click the “Word” button -it keeps saying “Can’t get window 1”

here’s my script so far:


tell application "Pages"
	activate
	set frontmost to true
	tell application "System Events"
		click menu item "Export." of menu 1 of menu bar item "Share" of menu bar 1 of process "Pages"
		click button "PDF" of sheet 1 of window 1
	end tell
end tell
tell application "System Events" to tell process "Pages"
	click menu item "Export." of menu 1 of menu bar item "Share" of menu bar 1
	click checkbox "Word" of radio group 1 of sheet 1 of window 1
end tell

^ still gives the same error

set docPath to choose file name
tell application "Pages"
	save front document as "Microsoft Word 97 - 2004 document" in docPath -- iWork 09
	-- save front document as "SLDocumentTypeMSWord" in docPath -- iWork 08
end tell

^ this however might work if I can find a way to find the path to the enclosing folder of the file I’m working on. Then I can just run the script and it saves a .doc copy of the file in the same folder as the current file.

Pages is fair enough to give us the path.


tell application "Pages" to tell document 1
	set oldname to name
	set oldPath to get path
	try
		set docPath to oldPath
	on error
		set oldPath to (path to documents folder as text) & oldname & ".pages"
		save in oldPath
	end try
	set docPath to text 1 thru -(1 + (count of "Pages")) of oldPath & "doc"
	save as "Microsoft Word 97 - 2004 document" in docPath
end tell

As Pages doesn’t return an error when the file was never saved, we must filter the case by ourselves.
We must save once as native document before being able to export.
Here I choose to save “never saved” documents in Documents folder.

Yvan KOENIG (from FRANCE dimanche 15 mars 2009 11:28:51)

Hi Yvan:

Thanks for this script. However, when I invoke it from the scripts menu it saves the current pages document in the home directory with the filename consisting of the entire document path. Any suggestions?

Thanks,
Mark

My fault.

I forgot than Pages returns an Unix path but need an HFS one to save.


tell application "Pages" to tell document 1
	set oldname to name
	set oldPath to get path
	try
		set docPath to oldPath
	on error
		set oldPath to (path to documents folder as text) & oldname & ".pages"
		save in oldPath
	end try
	tell application "System Events" to set oldPath to path of disk item oldPath
	if oldPath ends with ":" then set oldPath to text 1 thru -2 of oldPath (* useful is the app saves as packages *)
	set docPath to text 1 thru -(1 + (count of "Pages")) of oldPath & "doc"
	save as "Microsoft Word 97 - 2004 document" in docPath
end tell

Yvan KOENIG (from FRANCE samedi 11 avril 2009 18:38:21)

Like a charm.
Thanks again,
M.

Thanks for the script, guys - now is it possible to get this in a droplet so I can batch process a big pile of pages files?

Also, I’m a scripting idiot so I can’t get the original to work - are there some variables I need to plug in?
Thanks:D

Go to my iDisk :

http://public.me.com/koenigyvan

Download :
For_iWork:iWork '09:for_Pages09:batch_exportPages2PDF.zip

Yvan KOENIG (VALLAURIS, France) mardi 27 avril 2010 11:50:14

Fantastique! Tout à fait!

Merci beaucoup pour ton assistance!