Friday, May 27, 2022

#1 2022-05-13 10:53:41 pm

Jono
Member
Registered: 2008-07-08
Posts: 129

Firefox GUI menu bar script sometimes fails

Part of a script I'm trying to write hides the Bookmark Bar in Firefox, but the trouble is sometimes it works, sometimes it fails.

This is the original version I wrote:

Applescript:

tell application "Firefox" to activate
(* Hide Bookmark Bar *)
tell application "System Events"

   try
       click menu item "Never Show" of menu "Bookmarks Toolbar" of menu item "Bookmarks Toolbar" of menu "Toolbars" of menu item "Toolbars" of menu "View" of menu bar item "View" of menu bar 1 of process "Firefox"
   end try
   
end tell

As it failed sometimes I tweaked it slightly:

Applescript:

tell application "Firefox" to activate
(* Hide Bookmark Bar *)
tell application "System Events"
   
   tell menu "Bookmarks Toolbar" of menu item "Bookmarks Toolbar" of menu "Toolbars" of menu item "Toolbars" of menu "View" of menu bar item "View" of menu bar 1 of process "Firefox"
       
       if exists menu item "Never Show" then
           tell menu item "Never Show"
               click it
           end tell
       end if
       
   end tell
end tell

When running this version it sometimes shows that the "Never Show" menu bar item is false (doesn't exist).

If I keep running the script a few times the "Never Show" menu bar item 'becomes available' again, and will work.

Does anyone know why it sometimes works, but other times fails?

Offline

 

#2 2022-05-13 11:44:40 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2285

Re: Firefox GUI menu bar script sometimes fails

Waiting for each menu to appear is the same as waiting for windows to appear. Because they don't show up right away. Therefore, for stable operation, you should check the appearance of each menu  and submenu.

No need checking for menu items and submenu items, because they are not windows, like menus itself.

I don't have Firefox so I can't test the following script. But, in theory, it should work stably:

Applescript:


tell application "Firefox" to activate

(* Hide Bookmark Bar *)
tell application "System Events" to tell process "Firefox" to tell menu bar 1
   tell menu bar item "View"
       click it
       repeat until menu "View" exists -- wait for menu "View"
           delay 0.1
       end repeat
       tell menu item "Toolbars" of menu "View"
           click it
           repeat until menu "Toolbars" exists -- wait for menu "Toolbars"
               delay 0.1
           end repeat
           tell menu item "Bookmarks Toolbar" of menu "Toolbars" -- EDITED
               click it
               repeat until menu "Bookmarks Toolbar" exists -- wait for menu "Bookmarks Toolbar"
                   delay 0.1
               end repeat
               tell menu "Bookmarks Toolbar" of menu item "Bookmarks Toolbar"
                   click menu item "Never Show"
               end tell
           end tell
       end tell
   end tell
end tell

Last edited by KniazidisR (2022-05-14 12:05:17 pm)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2022-05-14 11:00:24 am

Jono
Member
Registered: 2008-07-08
Posts: 129

Re: Firefox GUI menu bar script sometimes fails

Thanks a lot. I kept getting errors at the part

   

Applescript:

       tell menu item "Bookmarks Toolbar"
               click it

But for some strange reason my script has started working OK now big_smile

Applescript:

tell application "Firefox" to activate

(* Hide Bookmark Bar *)
tell application "System Events"
   
   tell menu "Bookmarks Toolbar" of menu item "Bookmarks Toolbar" of menu "Toolbars" of menu item "Toolbars" of menu "View" of menu bar item "View" of menu bar 1 of process "Firefox"
       
       try
           tell menu item "Never Show"
               click it
           end tell
       end try
       
   end tell
end tell

Offline

 

#4 2022-05-14 12:06:43 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2285

Re: Firefox GUI menu bar script sometimes fails

It was one mistake. I edited the script.


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#5 2022-05-15 02:08:56 pm

Jono
Member
Registered: 2008-07-08
Posts: 129

Re: Firefox GUI menu bar script sometimes fails

KniazidisR wrote:

It was one mistake. I edited the script.


Ah, great. Thanks again!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)