Tuesday, November 19, 2019

#1 2019-10-20 05:04:21 am

NMG
Member
Registered: 2019-09-29
Posts: 29

Apple Pages Inspector hide or show

Can I check if the Inspector in Apple Pages is visible or not?


Filed under: Inspector, Apple Pages

Offline

 

#2 2019-10-20 09:35:41 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 712

Re: Apple Pages Inspector hide or show

Hiding/Showing Inspector section:

Applescript:


tell application "Pages" to activate
tell application "System Events" to keystroke "i" using {option down, command down}
delay 5 -- only to show result to user

Checking visible status of Inspector:

Applescript:


tell application "Pages" to activate
tell application "System Events" to tell process "Pages"
   try
       menu item "Hide Inspector" of menu 1 of menu item "Inspector" of menu 1 of menu bar item "View" of menu bar 1
       display dialog "Inspector is visible"
   on error
       display dialog "Inspector is hidden"
   end try
end tell

Last edited by KniazidisR (2019-10-20 09:57:24 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#3 2019-10-20 10:24:05 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Apple Pages Inspector hide or show

Here is a script which does the job without being linked to a system localisation.

Applescript:

set Show_loc to localized string "Show" from table "TSApplication" in bundle path to application "Pages"

tell application "Pages" to activate
tell application "System Events" to tell process "Pages"
   set frontmost to true
   
   tell menu bar 1 to tell menu bar item 8 to tell menu 1 to tell menu item 4 to tell menu 1
       set status to title of menu item -1 contains Show_loc
   end tell
end tell
tell application "Pages"
   if status then
       display dialog "No Inspector active"
   else
       display dialog "An Inspector is active"
   end if
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 20 octobre 2019  18:22:30

Offline

 

#4 2019-10-21 04:27:53 am

NMG
Member
Registered: 2019-09-29
Posts: 29

Re: Apple Pages Inspector hide or show

It works very well. Thank you.

I did not know about table "TSAApplication" I understand how it works here, but it is the first time I see it. Can you explain it more or suggest where I can learn? Thank you.

Offline

 

#5 2019-10-21 05:25:00 am

NMG
Member
Registered: 2019-09-29
Posts: 29

Re: Apple Pages Inspector hide or show

Applescript:


tell application "Pages" to activate
tell application "System Events" to tell process "Pages"
   try
       menu item "Hide Inspector" of menu 1 of menu item "Inspector" of menu 1 of menu bar item "View" of menu bar 1
       set "Isee" to "yes"
   on error
       set "Isee" to "no"
   end try
end tell

if Isee is equal to "yes" then
-- do something
else
-- do something else
end if

KniazidisR: Your solution works very well. Thank you. Now, I try to do something if inspector is visible and something else if it is not. This is what I tried. It works but it is not fast and it seems to need a delay before the conditional. Is there a better, faster solution?

Last edited by NMG (2019-10-21 05:29:33 am)

Offline

 

#6 2019-10-21 06:21:29 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 712

Re: Apple Pages Inspector hide or show

Hi, NMG.
First, you can't set literal string to other value (set "Isee" To "Yes").
Most time consumes launching of application "Pages" for 1st time. So, try to be Pages.app opened before running the script:

Applescript:


tell application "Pages" to activate
tell application "System Events" to tell process "Pages"
   if (menu item "Hide Inspector" of menu 1 of menu item "Inspector" of menu 1 of menu bar item "View" of menu bar 1 exists) then
       -- do something, when Inspector is open, for example:
       say "Inspector is visible"
   else
       -- do something else, when Inspector is closed, for example:
       say "Inspector is hidden"
   end if
end tell

Last edited by KniazidisR (2019-10-21 10:51:29 am)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#7 2019-10-21 07:26:34 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Apple Pages Inspector hide or show

NMG wrote:

It works very well. Thank you.

I did not know about table "TSAApplication" I understand how it works here, but it is the first time I see it. Can you explain it more or suggest where I can learn? Thank you.




It's a file available in one of the lproj folders in the Pages package containing datas used to localize several strings.

We use it with the function localized strings available in Standard Additions.

I used this function in numerous scripts posted here.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 21 octobre 2019  15:26:30

Offline

 

#8 2019-10-21 07:29:09 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Apple Pages Inspector hide or show

KniazidisR wrote:

Hi, NMG.
First, you can't set literal string to other value (set "Isee" To "Yes").
Most time consumes launching of application "Pages" for 1st time. So, try to be Pages.app opened before running the script:

Applescript:


tell application "Pages" to activate
tell application "System Events" to tell process "Pages"
   if (menu item "Hide Inspector" of menu 1 of menu item "Inspector" of menu 1 of menu bar item "View" of menu bar 1 exists) then
       -- do something, when Inspector is open, for example:
       say "Inspector is visble"
   else
       -- do something else, when Inspector is closed, for example:
       say "Inspector is hidden"
   end if
end tell




The main problem with such script is that it's linked to the language used by the system (here English).

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 21 octobre 2019  15:28:39

Offline

 

#9 2019-10-21 09:34:28 am

NMG
Member
Registered: 2019-09-29
Posts: 29

Re: Apple Pages Inspector hide or show

Yvan Koenig wrote:


The main problem with such script is that it's linked to the language used by the system (here English).




Uf! That is true. I did not think about the language. I cannot do a program for each language.

Offline

 

#10 2019-10-21 11:56:24 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Apple Pages Inspector hide or show

My script is not related to a language setting.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 21 octobre 2019  19:56:07

Offline

 

#11 2019-10-21 01:31:52 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 712

Re: Apple Pages Inspector hide or show

Yvan Koenig wrote:

My script is not related to a language setting.


Sure. I liked your trick, Yvan. I took note of it. Thanks.

Last edited by KniazidisR (2019-10-21 01:32:24 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#12 2019-10-21 01:34:18 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3635

Re: Apple Pages Inspector hide or show

Here is an enhanced version in which even the response is free from system settings.

Applescript:

tell me
   set path2Pages to path to application "Pages"
   set path2Preview to path to application "Preview"
end tell

set Show_loc to localized string "Show" from table "TSApplication" in bundle path2Pages --> "Afficher"
set On_loc to localized string "On" from table "TSCharts" in bundle path2Pages --> "Activé"
set Off_loc to localized string "Off" from table "TSCharts" in bundle path2Pages --> "Désactivé"
set Inspector_loc to localized string "Inspector" in bundle path2Preview --> "Inspecteur"

tell application "Pages" to activate
tell application "System Events" to tell process "Pages"
   set frontmost to true
   tell menu bar 1 to tell menu bar item 8 to tell menu 1 to tell menu item 4 to tell menu 1
       set status to title of menu item -1 contains Show_loc
   end tell
end tell
set answer to Inspector_loc & " : "
if status then
   set answer to answer & Off_loc -- "Inspecteur : Désactivé"
else
   set answer to answer & On_loc -- "Inspecteur : Activé"
end if

tell application "Pages" to display dialog answer

As you may see, I grab the localized strings from different tables.
As the bare string "Inspector" is not defined in Pages, I grab it from Preview which is supposed to be available for all of us.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 21 octobre 2019  21:31:10

Offline

 

#13 2019-10-22 10:19:16 am

NMG
Member
Registered: 2019-09-29
Posts: 29

Re: Apple Pages Inspector hide or show

Yvan Koenig wrote:



[applescript]
set Show_loc to localized string "Show" from table "TSApplication" in bundle path2Pages

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 21 octobre 2019  21:31:10



OK, fantastic! I have checked that it works well in different languages

Last edited by NMG (2019-10-23 03:16:23 am)

Offline

 

#14 2019-10-24 05:32:39 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5105

Re: Apple Pages Inspector hide or show

Yvan Koenig wrote:

The main problem with such script is that it's linked to the language used by the system (here English).


Here's another way. It works with Pages 5.6.2 in El Capitan and Pages 8.2 in Mojave, so I presume it works with combinations of versions in between too:

Applescript:

tell application "System Events"
   tell application process "Pages"
       set frontmost to true
       set inspectorShowing to false
       set splitterGroups to splitter group 1 of windows
       repeat with thisSplitterGroup in splitterGroups
           if (thisSplitterGroup's contents is not missing value) then
               -- This splitter group exists, so it's the one in the front document window.
               -- If it contains a radio group, the window's Inspector is showing.
               set inspectorShowing to (thisSplitterGroup's radio group 1 exists)
               exit repeat
           end if
       end repeat
   end tell
end tell
if (inspectorShowing) then
   -- do something, when Inspector is open, for example:
   say "Inspector is visble"
else
   -- do something else, when Inspector is closed, for example:
   say "Inspector is hidden"
end if


NG

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)