• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: UI and Page Setup "embedded elements"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UI and Page Setup "embedded elements"


  • Subject: Re: UI and Page Setup "embedded elements"
  • From: Yvan KOENIG <email@hidden>
  • Date: Sun, 15 Jan 2006 14:16:56 +0100

OK

Now I understand why I didn't found it. May archives are on an external HD !

Here is the script with added english comments.

--[SCRIPT mode_paysage]
 (*
 ATTENTION
 Ne pas placer ce script
 dans le dossier Scripts d'AppleWorks mais,
 sous forme de script compilé,
 dans le dossier Scripts du Système:
 "Utilisateurs:votreCompte:Bibliothèque:Scripts:".


CAUTION Don't store this script in the AppleWorks's Scripts folder. Save it as compiled script in the System's one: "Uses:yourAccount:Library:Scripts:"


Yvan KOENIG, Vallauris (FRANCE) le 25 février 2005 *)

 property french : false (* true = messages français
 • false = english messages *)

 property msg0 : "" -- globale
 property msg1 : "" -- globale
 property msg4 : "" -- globale
 property msg98 : "" -- globale
 property msg99 : "" -- globale

on run
try
if msg0 is "" then my prepareMessages() (* routine définissant les messages en fonction de la langue de travail choisie
• Handler building the messages accordingly to selected language *)
if my quelOS() < "1030" then error msg4 number 8004 (* routine identifiant le système d'exploitation actif
• Handler identifying the operating system *)
my controleGUI() (* routine vérifiant que le GUIscripting est activé
• Handler checking that GUIscripting is activated *)
my controlesDivers() (* comme son nom l'indique
• Do some useful checks *)
my modePaysage() (* routine activant le mode paysage
• Handler setting Landscape mode*)


 on error MsgErr number NroErr
 if NroErr is not -128 then
 beep 2
 tell application (my quiEstAuPremierPlan())
 display dialog "" & NroErr & " : " & MsgErr ¬
 buttons {msg99} with icon 0
 end tell -- application
 end if
 return
 end try
 end run

 -- ================== routines
 (* Une routine (handler) s'appelle
 par son nom suivi d'une paire de parenthèses
 encadrant d'éventuels paramètres)
 Il est souvent sage de placer le pronom "my" avant le nom
 afin de permettre au script de travailler sans ambiguité.
 Une routine est un segment de code encadré par les balises:
 on maBelleRoutine(paramètres éventuels)
 …
 end maBelleRoutine

 Lors de l'exécution elle récupère et exploite les paramètres éventuels.
 ATTENTION,
 si une variable utilisée dans le script principal
 n'est pas explicitement GLOBALE
 (définie comme Global ou Property)
 elle est invisible pour les routines.
 Il faut alors passer les dites variables sous forme de paramètre.
 De même, une variable définie à l'intérieur d'une routine
 est invisible pour le script appelant.
 Il faut alors la "renvoyer" au sript appelant.
 C'est ce que font ici les routines
 "quiEstAuPremierPlan" et "quelOS".

L'utilisation de routines facilite la maintenance des scripts.
Du fait du mode de fonctionnement interne d'AppleScript,
elle permet généralement d'accélérer les scripts.
Elle permet souvent de garantir une meilleure
gestion de l'environnement de travail.
C'est particulièrement vrai dans le cas d'AppleWorks, application fossile.
C'est le moyen idéal pour s'affranchir d'une
gestion souvent "aléatoire" de l'environnement
lorsqu'elle est laissée à la discrétion du couple AW - AS..
Nombre de scripts écrits au fil de la plume cafouillent
alors que le simple fait de les découper en routines,
ce qui oblige à définir explicitement l'environnement,
leur permet de fonctionner sans problème.
*)


 -- ==================
 (* renvoie le chemin vers l'application au premier plan
 • Returns the path to the application at front *)

on quiEstAuPremierPlan()
(* «constant afdregfp» est la forme canonique de frontmost application *)
-- return (path to «constant afdregfp» as string)
return (path to frontmost application as string)
end quiEstAuPremierPlan


 -- ==================
 (* appelée si le GUIscripting n'est pas activé.
 Affiche la préférence "Accès Universel"
 et demande de l'activer
 en cochant la préférence
 «Activez l’accès pour les périphériques d’aide»

 • Called if GUIscripting is not active
 Display "Universal Access" window
 and ask to check the preference
 «Activez l’accès pour les périphériques d’aide»
 *)

 on GUImissing()
 tell application "System Preferences"
 activate
 set current pane to ¬
 pane "com.apple.preference.universalaccess"
 display dialog msg98
 end tell -- to System Preferences
 end GUImissing

 -- ==================

(* Si le GUIscripting est actif, ouvre le dialogue "Format d'impression"
clique sur le bouton "Paysage" et presse Retour.


• If GUIscripting active,
open the dialog "Page Settings"
click in the button "Landscape"
and press Return
*)
on modePaysage()
tell application "AppleWorks 6"
activate
select document 1
(*
tell document 1
end tell
*)
end tell -- application "AppleWorks 6"
tell application "System Events"
if UI elements enabled then
tell process "AppleWorks 6"
click menu item 15 of menu (2 + 1) of menu bar 1
(* attention, pour le process "AppleWorks 6", le menu Pomme a le numéro 1
alors qu'il a le numéro 0 en AppleScript standard
De ce fait ici le menu "Fichier" a le numéro 3


• CAUTION, for process AppleWorks 6, the Apple Menu is #1
while it is #0 in standard Applescript.
So here, the File menu is numbered #3 *)
set nmi to get name of menu item 15 of menu (2 + 1) of menu bar 1
(* récupère le nom de l'article de menu
•Grab the name of menu item *)
set nw to text 1 thru -2 of nmi
(* récupère le nom de la fenêtre
• Grab the name of the window *)
(*
-- set wProps to (get properties of every UI element of window nw)
I used this instruction to get informations about UI elements available in the dialog


{{position:{733, 480}, maximum:missing value, name:"Format d’impression", size:{131, 16}, subrole:missing value, class:static text, minimum value:missing value, enabled:true, selected:missing value, role:"AXStaticText", help:missing value, title:missing value, value:"Format d’impression", orientation:missing value, description:"texte", focused:missing value},¬
{position:{576, 742}, maximum:missing value, name:missing value, size:{444, 55}, subrole:missing value, class:UI element, minimum value:missing value, enabled:true, selected:missing value, role:"AXUnknown", help:missing value, title:missing value, value:missing value, orientation:missing value, description:"inconnu", focused:missing value},¬
{position:{652, 521}, maximum:missing value, name:"Réglages :", size:{66, 20}, subrole:missing value, class:static text, minimum value:missing value, enabled:true, selected:missing value, role:"AXStaticText", help:missing value, title:"Réglages :", value:"Réglages :", orientation:missing value, description:"texte", focused:missing value},¬
{position:{596, 545}, maximum:missing value, name:missing value, size:{404, 194}, subrole:missing value, class:UI element, minimum value:missing value, enabled:true, selected:missing value, role:"AXUnknown", help:missing value, title:missing value, value:missing value, orientation:missing value, description:"inconnu", focused:missing value},¬
{position:{727, 520}, maximum:missing value, name:missing value, size:{244, 20}, subrole:missing value, class:pop up button, minimum value:missing value, enabled:true, selected:missing value, role:"AXPopUpButton", help:missing value, title:missing value, value:"Attributs de page", orientation:missing value, description:"bouton de menu local", focused:missing value}}


 A lot of elements are "missing":

 three are embedded in UI element 2
 button "Help"
 button "OK"
 button "Cancel"

 eleven are embedded in UI element 4
 static text "Pour :" and linked menu
 static text "EPSON SP830U Series (1,1)"
 static text "Papier :" and linked menu
 static text "21,00 cm x 29,70 cm"
 static text "Orientation :" and the linked group of three radio buttons
 static text "Échelle :" and the linked textField
 static text "%"

Is it a safe way to let the script grab the properties of these embedded elements (mainly the orientation buttons) ?

 *)
 set {x4, y4} to (get position of UI element 4 of window nw)
 set {sx4, sy4} to (get size of UI element 4 of window nw)
 set ofP to sx4 div 2
 (* La structure de cet objet n'est pas documentée
 mais le bouton Paysage est à mi-largeur,
 sa position verticale est apparemment constante (120) dans l'objet
 et sa hauteur est également constante (38),
 et le décalage des deux autres boutons est de 71 pixels.
 Par sécurité je clique à mi hauteur du bouton  (120 +19 = 139)

• The structure of this item is not documented
but the landscape button is in the middle of the width
Its vertical position is a constant (120) in the item
and its height is fixed too (38),
and the offset to the two others buttons is 71 pixels.
For safe I choosed to click at mid-height in the button (120 + 19 = 139 )*)
(*
click at {x4 + ofP - 71, y4 + 139} (* dans le bouton "Portrait" *)
*)
click at {x4 + ofP, y4 + 139} (* dans le bouton "Paysage-Landscape" *)
(*
click at {x4 + ofP + 71, y4 + 139} (* dans le bouton "Paysage inversé-Landscape reversed" *)
*)
keystroke return
end tell -- process "AppleWorks 6"
else
my GUImissing()
end if -- UI enabled
end tell -- application System Events
end modePaysage


 -- ==================
 (* vérifie que l'on utilise AW 6.x et qu'un document AW est ouvert
 • Check that we are using AW6.x and that an AW doc is open *)
 on controlesDivers()
 tell application "AppleWorks 6"
 activate
 -- Test version
 if "6." is not in (version as text) then ¬
 error msg0 number 8000
 if (count of every document) is 0 then error msg1 number 8001
 end tell -- AppleWorks
 end controlesDivers

 -- ==================
 (* vérifie que le GUIscripting est actif
 • Check that GUIscripting is active*)
 on controleGUI()
 tell application "System Events"
 if not UI elements enabled then my GUImissing()
 end tell -- to System Events
 end controleGUI

 -- =====================
 (* identifie le système d'exploitation actif
 • Grab running OS's ID*)
 on quelOS()
 try
 set hexData to system attribute "sysv"
 set hexString to {}
 repeat 4 times
 set hexString to ((hexData mod 16) as string) & hexString
 set hexData to hexData div 16
 end repeat
 set OS_version to hexString as string
 on error
 set OS_version to "0000"
 (* retournera "0000" si "system attribute" n'est pas reconnu
 • will return "0000" if the OS is not identified *)
 end try
 return OS_version
 end quelOS

-- =====================
(* fixe le contenu de properties messages en fonction de la langue de travail choisie
• Build the messages according to selected language (french or english)*)
on prepareMessages()
if french is true then
set msg0 to "Ce script n’est pas compatible" & return & ¬
"avec cette version d’AppleWorks." & return & ¬
"Veuillez utiliser une version 6.0" & return & ¬
"ou plus récente..."
set msg1 to "Aucun document ouvert"
set msg4 to "Requiert Mac OS 10.3 ou ultérieur."
set msg98 to "Le scriptage des éléments d’interface " & ¬
"est désactivé. " & ¬
"Cochez «Activez l’accès pour les périphériques d’aide»"
set msg99 to " Vu "
else
set msg0 to "This script is not compatible" & return & ¬
"with this version of AppleWorks." & return & ¬
"Please use version 6.0" & return & "or higher..."
set msg1 to "No open doc"
set msg4 to "Requires Mac OS 1.3 or higher."
set msg98 to "UI element scripting is not enabled. " & ¬
"Check “Enable access for assistive devices”"
set msg99 to " Oops "
end if
end prepareMessages


 --[/SCRIPT]

Yvan KOENIG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >UI and Page Setup "embedded elements" (From: David Hage <email@hidden>)

  • Prev by Date: UI and Page Setup "embedded elements"
  • Next by Date: scripting pdf
  • Previous by thread: UI and Page Setup "embedded elements"
  • Next by thread: Re: Re: UI and Page Setup "embedded elements"
  • Index(es):
    • Date
    • Thread