Applescript 2.0 for Pages

Hi

I was trying to make an Applescript for Pages in order to automate the process of exporting a document into a Word compatible one.

The problem is that I just don’t know how to script on 2.0 and the old commands just don’t work.

So far I had

Tell application “Pages” to activate
set frontmost to true
click menu item “Export.” of menu 1 of menu bar item “File” of menu bar 1 and click button “PDF” of radio group 1 of sheet 1 of window 1
click button “Next…” of sheet 1 of window 1
click button “Export” of sheet 1 of window 1
end tell

but I get a lot of errors.

If anyone here knows how to make this work with a key shortcut it would be great.

Thanks

Model: Macbook Pro 2.33 Ghz C2D with 2GB RAM
AppleScript: 2.0
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)

You’re attempting to GUI script Pages directly. You have to

tell application "System Events" to tell process "Pages"
activate
Click menu ...
etc.
end tell

Wait, I almost got it :slight_smile:
wait for an update on my post

Hi,

sorry, this cannot work at all
¢ the form tell application “xyz” to [command] is used for an one-liner
¢ the application should be activated before targeting System Events
¢ some delays must be performed to wait for certain UI elements

try this


activate application "Pages"
tell application "System Events" to tell process "Pages"
	click menu item "Export." of menu 1 of menu bar item "File" of menu bar 1
	repeat until exists sheet 1 of window 1
		delay 0.5
	end repeat
	tell sheet 1 of window 1
		perform action "AXPress" of checkbox "PDF" of radio group 1
		click button "Next..."
		repeat until exists button "Export"
			delay 0.5
		end repeat
		click button "Export"
	end tell
end tell

Ok, here it is

If you want Pages to Export to Word via a Scriptlet use this one

tell application “Pages”
activate
end tell
tell application “System Events”
with timeout of 300 seconds – 5 minutes
tell process “Pages”
tell menu bar 1
click menu item 13 of menu 3
end tell
repeat until sheet 1 of window 1 exists
end repeat

		tell sheet 1 of window 1
			tell radio group 1
				click checkbox "Word"
			end tell
			click button 1
		end tell
	end tell
	
end timeout

end tell

you can change “Word” to “PDF”, “RTF”, “Plain Text”

And that’s it. The only thing that I need to know is how to make this script work with a key shortcut under pages. I already saved the script with \scS.script but when I am running Pages, I put the shortcut and it doesn’t work. Any help will be appreciated

hehe, thanks StefanK, seems that if I had checked the forum earlier, I would have found your reply and saved me like 45 mins. :slight_smile:

Well, it still encouraged me to work on it and make my own script :slight_smile:

Thanks anyways