Re: Revisited: Selecting a pop up button value in a Print dialog
Re: Revisited: Selecting a pop up button value in a Print dialog
- Subject: Re: Revisited: Selecting a pop up button value in a Print dialog
- From: Yvan KOENIG <email@hidden>
- Date: Fri, 14 May 2010 17:56:09 +0200
Funny
I posted on Pages Discussions forum a script doing that about one
hour ago.
Here it is:
--{code}
--[SCRIPT 2Preview]
(*
Enregistrer le script en tant que Script : 2Preview.scpt
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Pa
ges:
Il vous faudra peut-être créer le dossier Pages et peut-être même
le dossier Applications.
menu Scripts > Pages > 2Preview
On peut également définir la property appInside to false
et implanter le script dans le dossier :
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:
L'application active sera identifiée automatiquement.
C'est pour ce cas qu'il est prévu différents noms de bouton ou
article de menus.
--=====
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: 2Preview.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.
menu Scripts > Pages > 2Preview
You may define the property appInside to false and store the script in :
<startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:
--=====
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/05/14
*)
--=====
property appInside : true
(*
true = the app is defined in the code
false = the app is identified thru info for
*)
property myApp : "Pages"
(*
Will be used if appInside is true.
may be Numbers or Keynote …
Store the script in the matching folder.
*)
property mItem : ""
--=====
on run
if appInside then
set the_App to myApp
else
set the_App to (info for (path to frontmost application))'s short name
end if -- appInside
my shortcut(the_App, "p", "c") -- Print…
set OSid to system attribute "sys2"
tell application the_App to activate
if 5 > OSid then
(*
Here if MacOs X 10.4.x
*)
tell application "System Events" to tell application process
the_App to perform action "AXPress" of last button of (first UI
element of sheet 1 of window 1 whose buttons is not {})
else
(*
Here if MacOs X 10.5 or higher
*)
if mItem is "" then tell application "Preview" to set mItem to get
localized string "CFBundleName" from table "InfoPlist" in bundle file
((path to applications folder as text) & "Preview.app")
(*
Now mItem is stored in the script which will no longer grab it from
the resource file.
*)
if OSid = 5 then
(*
Here if MacOs X 10.5.x
*)
tell application "System Events" to tell application process
the_App to tell window 1 to tell sheet 1
if appInside then
click button mItem
else
set mItems to name of buttons
if mItems contains mItem then
click button mItem
else if mItems contains (mItem & "…") then
click button (mItem & "…")
else if mItems contains (mItem & "...") then
click button (mItem & "...")
else
if my parleAnglais() then
error "Can‘t find a “Preview” button !"
else
error "Il n‘y a pas de bouton « Aperçu » !"
end if -- parleAnglais()
end if -- mItems…
end if -- appInside…
end tell -- System Events
else
(*
Here if MacOs X 10.6 or higher
*)
tell application "System Events" to tell application process
the_App to tell window 1 to tell sheet 1
click menu button "PDF"
delay 0.1
tell menu button "PDF" to tell menu 1
if appInside then
click menu item mItem
else
set mItems to name of menu items
if mItems contains mItem then
click menu item mItem
else if mItems contains (mItem & "…") then
click menu item (mItem & "…")
else if mItems contains (mItem & "...") then
click menu item (mItem & "...")
else
if my parleAnglais() then
error "Can’t find a “Preview” menu item !"
else
error "Il n’y a pas de d’article de menu « Aperçu » !"
end if -- parleAnglais()
end if -- mItems…
end if -- appInside…
end tell -- menu button…
end tell -- System Events
end if -- OSid =…
end if -- 5 > …
end run
--=====
on activateGUIscripting()
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true
(* to be sure than GUI scripting will be active *)
end tell
end activateGUIscripting
--=====
(*
==== Uses GUIscripting ====
*)
(*
This handler may be used to 'type' text, invisible characters if the
third parameter is an empty string.
It may be used to 'type' keyboard shortcuts if the third parameter
describe the required modifier keys.
*)
on shortcut(a, t, d)
local k
tell application a to activate
tell application "System Events" to tell application process a
set frontmost to true
try
t * 1
if d is "" then
key code t
else if d is "c" then
key code t using {command down}
else if d is "a" then
key code t using {option down}
else if d is "k" then
key code t using {control down}
else if d is "s" then
key code t using {shift down}
else if d is in {"ac", "ca"} then
key code t using {command down, option down}
else if d is in {"as", "sa"} then
key code t using {shift down, option down}
else if d is in {"sc", "cs"} then
key code t using {command down, shift down}
else if d is in {"kc", "ck"} then
key code t using {command down, control down}
else if d is in {"ks", "sk"} then
key code t using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
key code t using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
key code t using {command down, shift down, option down}
end if
on error
repeat with k in t
if d is "" then
keystroke (k as text)
else if d is "c" then
keystroke (k as text) using {command down}
else if d is "a" then
keystroke k using {option down}
else if d is "k" then
keystroke (k as text) using {control down}
else if d is "s" then
keystroke k using {shift down}
else if d is in {"ac", "ca"} then
keystroke (k as text) using {command down, option down}
else if d is in {"as", "sa"} then
keystroke (k as text) using {shift down, option down}
else if d is in {"sc", "cs"} then
keystroke (k as text) using {command down, shift down}
else if d is in {"kc", "ck"} then
keystroke (k as text) using {command down, control down}
else if d is in {"ks", "sk"} then
keystroke (k as text) using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k"
then
keystroke (k as text) using {command down, shift down, control
down}
else if (d contains "c") and (d contains "s") and d contains "a"
then
keystroke (k as text) using {command down, shift down, option down}
end if
end repeat
end try
end tell
end shortcut
--=====
on parleAnglais()
local z
try
tell application "Pages" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
--[/SCRIPT]
--{code}
Yvan KOENIG (VALLAURIS, France) vendredi 14 mai 2010 17:55:35
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden