Apple Pages Inspector hide or show

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

Hiding/Showing Inspector section:


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:


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

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

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

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.


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?

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:


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

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

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

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

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

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

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

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

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

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:

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