Tuesday, May 21, 2019

#1 2019-02-28 06:28:05 am

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

Select Finder menu bar item and ensure it's toggled on

I have a script to open a folder and set the bounds, view etc. but I'm struggling with one part of it.

I want it to always make sure the 'Use Groups' toggle is enabled/selected (Finder > View > Use Groups), but my script doesn't know whether it's already set to on or off so just 'blindly toggles it'.

Applescript:

tell application "Finder"
   if computer name of (system info) is "iMac 5K" then
       set theBounds to ({670, 100, 1890, 1268} as rectangle)
   end if
   if computer name of (system info) is "MacBook Pro" then
       set theBounds to ({280, 23, 1400, 995} as rectangle)
   end if
   
   set NewWindow to make new Finder window
   set target of NewWindow to (path to desktop folder as text)
   
   tell Finder window 1
       set the bounds to theBounds
       set its sidebar width to 200
       set its toolbar visible to true
       set current view to list view
       
       tell its list view options
           set the sort column to modification date column
           set sort direction of column id modification date column to normal
           set icon size to small icon
       end tell
   end tell
   activate
end tell


(* Help! *)
tell application "System Events"
   click menu item ¬
       "Use Groups" in menu "View" of menu bar item ¬
       "View" in menu bar 1 of process "Finder"
end tell

Is there a way to make sure it's always enabled, or look at whether it's enabled or not and act accordingly?

Offline

 

#2 2019-02-28 07:23:02 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11560
Website

Re: Select Finder menu bar item and ensure it's toggled on

You have to check if the menu item exists and if the attribute AXMenuItemMarkChar is the checkmark character

Applescript:


tell application "System Events"
   tell menu "View" of menu bar item "View" in menu bar 1 of process "Finder"
       if exists menu item "Use Groups" then
           tell menu item "Use Groups"
               if value of attribute "AXMenuItemMarkChar" is not "✓" then
                   click it
               end if
           end tell
       end if
   end tell
end tell


regards

Stefan

Offline

 

#3 2019-02-28 08:29:24 am

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

Re: Select Finder menu bar item and ensure it's toggled on

On my Finder in French I see no item resembling to "Use Groups".
Is it an item introduced by Mojave ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 28 février 2019 15:29:15

Offline

 

#4 2019-02-28 08:42:49 am

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

Re: Select Finder menu bar item and ensure it's toggled on

Perfect, thanks Stefan!

Yvan Koenig wrote:

On my Finder in French I see no item resembling to "Use Groups".
Is it an item introduced by Mojave ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 28 février 2019 15:29:15



No, it was there before Mojave (although might have been renamed in Mojave).

pb8Z2X+

Offline

 

#5 2019-02-28 08:49:28 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11560
Website

Re: Select Finder menu bar item and ensure it's toggled on

@Yvan, yes, Use Groups appears only in Mojave


regards

Stefan

Offline

 

#6 2019-02-28 09:20:48 am

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

Re: Select Finder menu bar item and ensure it's toggled on

Thank you Stefan.
It seems that the screenshot posted by jono was done under Mojave.
Here, under High Sierra the menu items are:


{"Par icônes", "Par liste", "Par colonnes", "Sous forme de Cover Flow", missing value, "Aligner", "Aligner la sélection", "Aligner par", "Organiser par", "Trier par", missing value, "Masquer la barre d’onglets", "Masquer la barre du chemin d’accès", "Masquer la barre d’état", "Masquer la barre latérale", "Masquer l’aperçu", missing value, "Barre d’outils", "Personnaliser la barre d’outils…", missing value, "Afficher les options de présentation", missing value, "Activer le mode plein écran"}

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 28 février 2019 16:20:41

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)