Hi,
I want to open the Typography window in Pages with this script.
It works with Pages 5 and Pages 09 when run from Script Editor in El Capitan.
However, if the script runs from the script menu in the menu bar it stops after showing the Fonts window.
Thanks in advance for your help.
tell application "System Events" to tell process "Pages"
set frontmost to true
keystroke "t" using command down -- Show Fonts
-- script stops here when run from the script menu
tell menu button 1 of group 1 of toolbar 1 of window 1
click
tell menu 1
click menu item "Typography..." --opens Typography window
end tell
end tell
end tell
set path2Pages to (path to application id "com.apple.iWork.Pages") as «class furl»
set ShowFonts_loc to localized string "Show Fonts" from table "TSApplication" in bundle path2Pages
--> "Afficher les polices"
set Fonts_loc to localized string "Fonts" from table "TSText" in bundle path2Pages
--> "Polices"
# BINGO, I got it !
(path to library folder from system domain as text) & "CoreServices:Photo Library Migration Utility.app:Contents:Frameworks:iLifePageLayout.framework:"
set Typography_loc to localized string "KHCarouselCardBindingPremium" from table "Localizable" in bundle (result as «class furl»)
--> "Typographie"
if Typography_loc is not "Typographie" then
set Typography_loc to "Typography" # EDIT ACCORDING TO THE LANGUAGE IN USE.
end if
tell application "System Events" to tell process "Pages"
set frontmost to true
# Is there a floating window named Typography_loc ?
set avail to exists (first window whose (name is Typography_loc) and subrole is "AXFloatingWindow")
tell menu bar 1 to tell menu bar item 6 to tell menu 1 to tell menu item 1 to tell menu 1
set maybe to name of menu item 1
end tell
if maybe is ShowFonts_loc then
# The floating window Fonts_loc not open, open it.
keystroke "t" using command down -- Show Fonts
repeat 10 times
if exists (window 1 whose (name is Fonts_loc) and subrole is "AXFloatingWindow") then
exit repeat
end if
delay 0.01
end repeat
end if
tell (first window whose (name is Fonts_loc) and subrole is "AXFloatingWindow")
tell group 1 of toolbar 1
-- class of UI elements --> {menu button}
tell menu button 1
click
tell menu 1
-- name of menu items -->{"Ajouter aux favoris", "Afficher l'aperçu", missing value, "Couleur.", "Caractères.", "Typographie.", missing value, "Modifier les tailles.", missing value, "Gérer les polices."}
if avail then
# The Typography floating window is already open
click menu item 3 # missing value to close the local menu
else
click (first menu item whose name contains Typography_loc)
--> click menu item "Typographie." of menu 1 of menu button 1 of group 1 of toolbar 1 of window "Polices" of application process "Pages"# open the Typography floating window
end if
end tell # menu 1
end tell # menu button 1
end tell # group 1
end tell # floating window
end tell
At last I found a resource file containing the localized strings for the Typography string so now everything is localization free.
I was too optimistic. The found resource contains “Typographie” in french but contains “Letterpress” in English. I wrongly assumed that it was “Typography”
Made some changes to be sure that we are really triggering the floating window named Fonts_loc in case of a document window is named the same.
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) mercredi 8 juin 2016 18:27:56
Hi Yvan,
awesome, as always. Thank you very much.
Thank for the feedback.
At last I found a way to extract the localized string for “Typography” so I edited the script above which is now localization free.
I’m wondering if it is really useful to open the Fonts floating window if the Typography one is already open.
The version below doesn’t open the dialog in this case.
set path2Pages to (path to application id "com.apple.iWork.Pages") as «class furl»
set ShowFonts_loc to localized string "Show Fonts" from table "TSApplication" in bundle path2Pages
--> "Afficher les polices"
set Fonts_loc to localized string "Fonts" from table "TSText" in bundle path2Pages
--> "Polices"
# BINGO, I got it !
(path to library folder from system domain as text) & "CoreServices:Photo Library Migration Utility.app:Contents:Frameworks:iLifePageLayout.framework:"
set Typography_loc to localized string "KHCarouselCardBindingPremium" from table "Localizable" in bundle (result as «class furl»)
--> "Typographie"
if Typography_loc is not "Typographie" then
set Typography_loc to "Typography" # EDIT ACCORDING TO THE LANGUAGE IN USE.
end if
tell application "System Events" to tell process "Pages"
set frontmost to true
set avail to exists (first window whose (name is Typography_loc) and subrole is "AXFloatingWindow")
if not avail then
tell menu bar 1 to tell menu bar item 6 to tell menu 1 to tell menu item 1 to tell menu 1
set maybe to name of menu item 1
end tell
if maybe is ShowFonts_loc then
# The floating window Fonts_loc not open, open it.
keystroke "t" using command down -- Show Fonts
repeat 10 times
if exists (window 1 whose (name is Fonts_loc) and subrole is "AXFloatingWindow") then
exit repeat
end if
delay 0.01
end repeat
end if
# The floating window named Typography_loc is not open so, open it?
tell (first window whose (name is Fonts_loc) and subrole is "AXFloatingWindow")
tell group 1 of toolbar 1
-- class of UI elements --> {menu button}
tell menu button 1
click
tell menu 1
-- name of menu items -->{"Ajouter aux favoris", "Afficher l'aperçu", missing value, "Couleur.", "Caractères.", "Typographie.", missing value, "Modifier les tailles.", missing value, "Gérer les polices."}
click (first menu item whose name contains Typography_loc) # open the Typography floating window
--> click menu item "Typographie." of menu 1 of menu button 1 of group 1 of toolbar 1 of window "Polices" of application process "Pages"
end tell # menu 1
end tell # menu button 1
end tell # group 1
end tell # floating window
end if # avail ?
end tell
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) jeudi 9 juin 2016 15:39:43
Hi Yvan,
thank you very much for the updated script.
Unfortunately I get an error (Pages 5, El Capitan)
error “System Events got an error: Can’t get menu item 1 of menu 1 of menu button 1 of group 1 of toolbar 1 of window 1 of process "Pages" whose name = "Fonts" and subrole = "AXFloatingWindow" whose name contains "Letterpress". Invalid index.” number -1719
I wonder if it is possible to open the Typography window directly without opening the Fonts window.
Thanks again.
Oops, I know what’s wrong.
When I found an occurence of “Typographie” in the resources of the framework defined by :
[format](path to library folder from system domain as text) & “CoreServices:Photo Library Migration Utility.app:Contents:Frameworks:iLifePageLayout.framework:”[/format]
I didn’t checked that it was the french version of “Typography”.
In fact the English string available in the resource is “Letterpress”
Please, edit the beginning of the script as :
set path2Pages to (path to application id "com.apple.iWork.Pages") as «class furl»
set ShowFonts_loc to localized string "Show Fonts" from table "TSApplication" in bundle path2Pages
--> "Afficher les polices"
set Fonts_loc to localized string "Fonts" from table "TSText" in bundle path2Pages
--> "Polices"
# BINGO, I got it !
(path to library folder from system domain as text) & "CoreServices:Photo Library Migration Utility.app:Contents:Frameworks:iLifePageLayout.framework:"
set Typography_loc to localized string "KHCarouselCardBindingPremium" from table "Localizable" in bundle (result as «class furl»)
--> "Typographie"
if Typography_loc is not "Typographie" then
set Typography_loc to "Typography" # EDIT ACCORDING TO THE LANGUAGE IN USE.
end if
Of course I will edit the scripts after posting this message.
Oops, I forgot to answer a question.
As far as I know we can’t open the Typography window without opening the window Fonts.
If it exists, it respond to the action “AXRaise” but if it’s not open we get :
error “Erreur dans System Events : Il est impossible d’obtenir window "Typographie" of process "Pages".” number -1728 from window “Typographie” of process “Pages”
You may check what I wrote with this short script:
tell application "System Events" to tell process "Pages"
set frontmost to true
tell window "Typography" to perform action "AXRaise"
end tell
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) jeudi 9 juin 2016 18:47:50
the updated script works very well.
I get the same error when trying to open the window Typography directly. I will try to close it after the Fonts window is displayed.
Thanks a lot.
It seems that my message was not clear : you can’t open the Typography window directly.
With the 1st script you may :
(1) open the Fonts window then open the Typography window
(2) leave the two fonts open if the Typography one was open.
With the 2d script you may :
(1) open the Fonts window then open the Typography window
(2) leave the Typography window open if it was open when you called the script.
The difference is that with the second, if you open the two windows once then close the Fonts one, you may continue to work with only the Typography window open. Of course it would be neater to not re-run the script after closing the Fonts window but it’s easy to run the script “by error”.
Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) jeudi 9 juin 2016 21:44:03