Hello
Thanks to Chris Nebel, here is an enhanced version. Setting the ruler units is now OK.
--[SCRIPT] set theApp to "Pages"
tell application theApp to set pp to path to it
tell application theApp -- it's easier than specifying the app's pathname
set lstrShowInspector to localized string "Show Inspector" set lstrHideInspector to localized string "Hide Inspector"
set lstrSmoothPath to localized string "Smooth Path" from table "UndoStrings" set lstrWrapStyle to localized string "Wrap Style" from table "UndoStrings" set lstrWrapTreshold to localized string "Wrap Threshold" from table "UndoStrings"
set lstrNewInspector to localized string "New Inspector" -- localized unreachable set lstrItemPreferences to localized string "Preferences…" -- localized unreachable set lstrCentimeter to localized string "Centimeter" -- localized unreachable end tell
tell application "Pages" set ruler units to picas if ruler units is not centimeters then set ruler units to centimeters set runits to ruler units end tell
tell application theApp activate tell application "System Events" to tell process theApp to set ll to name of every menu item of menu 8 of menu bar 1 end tell
repeat with ii from 1 to count of ll if ll's item ii is in {lstrShowInspector, lstrHideInspector} then set lstrNewInspector to ll's item (ii + 1) exit repeat end if end repeat
if ll contains lstrShowInspector then display dialog "No Inspector is displaid" & return & "item " & ii & " is " & lstrNewInspector else display dialog "At least one Inspector is displaid" & return & "item " & ii & " is " & lstrNewInspector end if
tell application theApp set pp to localized string "%@ Preferences" if pp starts with "%@ " then set p to (text 4 thru end of pp) else set p to (text 1 thru -4 of pp) end if set lstrItemPreferences to p & "…" -- activate tell application "System Events" tell process theApp click menu item lstrItemPreferences of menu 2 of menu bar 1 set _ to get name of every window repeat with i in _ if i contains p then set wPrefs to i exit repeat end if end repeat
tell window wPrefs to set bb to title of buttons of UI element 4
if bb's item 1 is not in wPrefs then (* activate "Préférences Général" *) click button 1 of UI element 4 of window wPrefs set _ to get name of every window repeat with i in _ if i contains p then set wPrefs to i exit repeat end if end repeat end if
tell window wPrefs -- fenêtre Préférences get properties of pop up button 2 click pop up button 2 (* Unités de la règle *) get properties of UI elements -- -- how may I grab the names of the four menu items -- I want to set it to centimeters/centimètres -- end tell -- fenêtre Préférences end tell -- process theApp end tell -- application System Events end tell -- application theApp --[/SCRIPT]
The remaining problem is: How may I trigger a contextual menu ?
Yvan KOENIG |