How do I use Applescript GUI to control Safari's Page Setup?

Hi,

This is my first post at this forum, so if there’s a better way to submit questions, please let me know. Quick background – my Applescript training is based on the Applescript for Absolute Starters PDF (very easy stuff, especially if you’re an old BASIC user like me) and a few things I’ve stumbled across online, plus whatever my limited experience has taught me. My main interest now is in GUI programming via Applescript, writing scripts for work.

So, here’s my current problem – I want to use Applescript to open Safari’s Page Setup screen and select a different printer and a different paper size. After that, I’ll want to choose some Print screen options, but I’ll cross that bridge when I get to it. If you want to be picky, I’m actually going to use the technique in MultiAd Creator 7, but I figure Safari is more widespread and, for the Page Setup, the UI Element Inspector yields congruent results in Safari as with Creator, so the results should be transferable. I can use Applescript’s GUI capability to open the Page Setup screen, but then I’m stuck. There are three dropdown menus – the first one I can ignore, but I want to change the options on the next two.

Here are the results of using the UIEI in the Page Setup screen:

On top of the Format dropdown menu:

<AXApplication: “Safari”>
<AXSheet: “Page Setup”>


Attributes:
AXRole: “AXPopUpButton”
AXRoleDescription: “pop up button”
AXChildren: “<array of size 0>”
AXParent: “”
AXWindow: “<AXSheet: “Page Setup”>”
AXPosition: “x=442 y=109”
AXSize: “w=210 h=20”
AXEnabled: “1”
AXValue: “HP Laserjet 8000 - Adcomp”

Actions:
AXPress - press

UIEI on top of Paper Size dropdown menu:

<AXApplication: “Safari”>
<AXSheet: “Page Setup”>


Attributes:
AXRole: “AXPopUpButton”
AXRoleDescription: “pop up button”
AXChildren: “<array of size 0>”
AXParent: “”
AXWindow: “<AXSheet: “Page Setup”>”
AXPosition: “x=442 y=161”
AXSize: “w=210 h=20”
AXEnabled: “1”
AXValue: “US Letter”

Actions:
AXPress - press

UIEI on Prinergy Refiner option for the first dropdown menu, which is what I want instead of HP Laserjet 8000 - Adcomp:

<AXApplication: “Safari”>
<AXSheet: “Page Setup”>



<AXMenuItem: “Prinergy Refiner”>

Attributes:
AXRole: “AXMenuItem”
AXRoleDescription: “menu item”
AXChildren: “(null)”
AXParent: “”
AXTitle: “Prinergy Refiner”
AXEnabled: “1”
AXPosition: “x=443 y=72”
AXSize: “w=229 h=19”
AXSelectedChildren: “<array of size 0>”
AXVisibleChildren: “<array of size 0>”
AXHelp: “(null)”
AXMenuItemCmdChar: "
AXMenuItemCmdVirtualKey: “(null)”
AXMenuItemCmdGlyph: “(null)”
AXMenuItemCmdModifiers: “0”
AXMenuItemMarkChar: "

Actions:
AXCancel - cancels menu tracking
AXPick - selects a menu item
AXPress - selects a menu item

UIEI on Crossword paper size in the second dropdown menu, which is what I want instead of US Letter:

<AXApplication: “Safari”>
<AXSheet: “Page Setup”>



<AXMenuItem: “crossword”>

Attributes:
AXRole: “AXMenuItem”
AXRoleDescription: “menu item”
AXChildren: “(null)”
AXParent: “”
AXTitle: “crossword”
AXEnabled: “1”
AXPosition: “x=443 y=535”
AXSize: “w=188 h=19”
AXSelectedChildren: “<array of size 0>”
AXVisibleChildren: “<array of size 0>”
AXHelp: “(null)”
AXMenuItemCmdChar: "
AXMenuItemCmdVirtualKey: “(null)”
AXMenuItemCmdGlyph: “(null)”
AXMenuItemCmdModifiers: “0”
AXMenuItemMarkChar: "

Actions:
AXCancel - cancels menu tracking
AXPick - selects a menu item
AXPress - selects a menu item

That’s the situation. I hope my description hasn’t been too confusing. If anyone can tell me how to change from the Laserjet to Prinergy Refiner and from US Letter to Crossword, I’d be grateful.

Thank you very much.

AppleScript: 1.9.3
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

Not sure if this is what you need but try this:

tell application "Safari"
	set PRINT_CONFIG to {target printer:"Prinergy Refiner"}
	print document 1 with properties PRINT_CONFIG
end tell

CarbonQuark

Thanks for the idea, but the scriptlet gave me a syntax error with the word “printer” highlighted:
‘Expected “,” or “}” but found identifier’

For what it’s worth, I was running the scriptlet alone, so there was no other code to interfere with it.