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’.
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?
You have to check if the menu item exists and if the attribute AXMenuItemMarkChar is the checkmark character
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