Maybe this script written to set the document orientation in Pages may be used as a starting point.
--{code}
--[SCRIPT set_document_orientation]
(*
Enregistrer le script en tant que Script : set_document_orientation.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Pages:
Il vous faudra peut-être créer le dossier Pages et peut-être même le dossier Applications.
Ouvrir un document Pages
aller au menu Scripts , choisir Pages puis choisir set_document_orientation
Passer la chaîne "Portrait" pour adopter le format 'portrait'.
Toute autre chaîne activera le mode paysage.
Je me suis amusé à passer le titre d'une œuvre de Charles MINGUS.
Vous avez sans doute compris que ce sont surtout les routines qui sont utiles.
N'hésitez pas à les intégrer à un ou plusieurs scripts plus élaborés.
--=====
L'aide du Finder explique:
L'Utilitaire AppleScript permet d'activer le Menu des scripts :
Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case "Afficher le menu des scripts dans la barre de menus".
--=====
Save the script as a Script: set_document_orientation.scpt
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
Maybe you would have to create the folder Pages and even the folder Applications by yourself.
Open a Pages document
go to the Scripts Menu, choose Pages, then choose "set_document_orientation"
Pass the string "portrait" if you want to use the portrait orientation.
Pass any other string to use the landscape one.
Here I play the fool passing the title of a Charles MINGUS composition.
In fact the script is just a demo.
A really useful script would embed the handlers so that you may rule the document orientaion from it.
--=====
The Finder's Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the "Show Script Menu in menu bar" checkbox.
--=====
Yvan KOENIG (VALLAURIS, France)
2010/07/20
2010/07/21 -- splitted the original script in two ones.
2010/07/22 -- corrected a stupid typo
*)
--=====
(* I define the target application in a property so that I change only this single value
when I want to run Pages '08 which is named Pages08 on my machines
*)
property theApp : "Pages"
--=====
on run
local wName
my activateGUIscripting()
if theApp does not contain "Pages" then -- Oops, I forgot an odd underscore in the variable name
if my parleAnglais() then
error "Script dedicated to Pages !"
else
error "Script dédié à Pages !"
end if -- parleAnglais
end if
tell application theApp
try
set wName to name of window 1
tell document 1
--
end tell
on error (* Can't get name of window 1 *)
if my parleAnglais() then
error "There is no "" & theApp & "" window open !"
else
error "il n'y a pas de fenêtre « " & theApp & "» ouverte !"
end if -- parleAnglais
end try
end tell -- theApp
my setPagesDocumentOrientation(theApp, "All the things you could be by now if Sigmund Freud's wife was your mother", wName)
end run
--=====
on parleAnglais()
local z
try
tell application theApp to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
on getLocalizedString(a, x)
tell application a to return localized string x
end getLocalizedString
--=====
on activateGUIscripting()
(* to be sure than GUI scripting will be active *)
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true
end tell
end activateGUIscripting
--=====
on setPagesDocumentOrientation(the_app, whichOne, w_name)
if 5 > (system attribute "sys2") then
(* 10.4.11 *)
set Cancel_loc to my getLocalizedString("Finder", "AL1") -- Annuler
set Continue_loc to my getLocalizedString("Finder", "AL3") -- Continuer
if my parleAnglais() then
display dialog "Script unable to rule orientation" & return & "under Mac Os X 10.4.x" buttons {Cancel_loc, Continue_loc} default button 2
else
display dialog "Script incapable de régir l'orientation" & return & "sous Mac Os X 10.4.x" buttons {Cancel_loc, Continue_loc} default button 2
end if -- parleAnglais
end if -- 5 > (system attribute.
tell application the_app to activate
tell application "System Events" to tell application process the_app
(* trigger the menu item File > Page Setup. *)
keystroke "p" using {command down, shift down}
(* Wait for the "Page Setup" sheet *)
repeat until exists sheet 1 of window w_name
delay 0.1
end repeat
(*
Now, the sheet is available, we may trigger an UI element *)
tell sheet 1 of window w_name
if whichOne is "portrait" then
click UI element 1 of radio group 1 (* radio button if 10.5.x, checkbox if 10.6.x *)
else
click UI element 2 of radio group 1 (* radio button if 10.5.x, checkbox if 10.6.x *)
end if
-- title of button 1 (* "OK" *)
click button 1
end tell --sheet 1 of window
end tell -- System Events
end setPagesDocumentOrientation
(*
If it's macOs X 10.5.x,
get properties of UI element 1 of radio group 1
returns :
{size:{38, 38}, focused:false, description:"case à cocher", subrole:missing value, minimum value:missing value, enabled:true, role:"AXCheckBox", name:missing value, value:1, selected:missing value, class:checkbox, title:"", help:missing value, position:{1249, 319}, orientation:missing value, entire contents:{}, maximum value:missing value}
if it's macOs X 10.6.x,
get properties of UI element 2 of radio group 1
returns :
{minimum value:missing value, orientation:missing value, position:{1353, 389}, class:radio button, role description:"bouton radio", accessibility description:"Paysage", focused:false, title:"", size:{38, 38}, value:1, help:missing value, enabled:true, maximum value:missing value, role:"AXRadioButton", entire contents:{}, subrole:missing value, selected:missing value, name:missing value, description:"Paysage"}
I use the generic "UI element" name which apply to radio button as well as to checkbox.
Under 10.4 these iteems are of a third kind : button. Maybe they will use a fourth one in 10.7 ;-)
*)
--=====
--[/SCRIPT]
--{code}
Yvan KOENIG (VALLAURIS, France) jeudi 29 juillet 2010 20:19:35