Toggling Folder "View Options"

Again, maybe I'm not searching properly. Or maybe I'm being too specific.

What would be the best workflow to switch the various parameters in the View Options window, and assigning each preset to a particular shortcut? i.e. cmd+opt+[1-9]

Like so:

Nov-25-2021 01-17-11

I keep dipping into KM every so often, but not having enough time i tend to have periods of not using and forgetting the basics. Am I correct in thinking the only way to do this is by emulating cmd+J and then "visually" searching the screen for the View Options window, and then manually setting mouse.click to specific XYcoords, one for each parameter that i want changed?

Or is there a better way, like telling KM:

select(window.ViewOptions)

and

ViewOptions.selectDropdown(GroupBy:Name)

<fantasizing here of course>

Hey David,

Many options are available in the Finder's View menu.

Some view options are AppleScriptable, but Apple removed a bunch of scripting options waaay back around macOS Mountain Lion.

You can use AppleScript UI-Scripting to manage the view options dialog. It's a bit slow, but it's far faster than doing it by hand.

This script may require adjusting for versions of macOS later than Mojave.

This is one of those places where Apple dropped the ball in the mud and left it there...

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/01 13:04
# dMod: 2021/11/25 23:34
# Appl: System Events
# Task: Set List View Attributes
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Set, @List-View, @Attributes
# Test: Tested on macOS 10.14.6 Mojave with Keyboard Maestro 10.0.1
--------------------------------------------------------

setFrontFinderWindowToListView()

tell application "System Events"
   tell application process "Finder"
      set frontmost to true
      
      if (value of attribute "AXSubrole" of front window is "AXSystemFloatingWindow") = false then
         
         --» Show View Options for Finder Window
         tell menu bar 1
            tell menu bar item "View"
               tell menu 1
                  tell menu item "Show View Options"
                     perform action "AXPress"
                  end tell
               end tell
            end tell
         end tell
         
         set theClock to 0
         
         repeat until front window's subrole is "AXSystemFloatingWindow"
            if theClock ≥ 0.5 then
               beep
               error "Problem opening window list-view prefs!"
            else
               set theClock to theClock + 0.1
               delay 0.1
            end if
         end repeat
         
      end if
      
      tell (first window whose subrole is "AXSystemFloatingWindow")
         
         tell group 1
            if (exists of checkbox "Date Modified") = false then
               setFrontFinderWindowToIconView() of me
               delay 0.15
               setFrontFinderWindowToListView() of me
               delay 0.15
            end if
         end tell
         
         tell checkbox "Always open in list view"
            if its value = 0 then
               click it
            end if
         end tell
         tell checkbox "Browse in list view"
            if its value = 0 then
               click it
            end if
         end tell
         
         tell (first pop up button whose name is "Group By:")
            if value ≠ "None" then
               click
               tell menu 1
                  click menu item "None"
               end tell
            end if
         end tell
         tell (first pop up button whose name is "Sort By:")
            if value ≠ "Name" then
               click
               tell menu 1
                  click menu item "Name"
               end tell
            end if
         end tell
         
         tell group 1
            
            tell checkbox "Date Modified"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Date Created"
               if its value = 0 then
                  click it
               end if
            end tell
            tell checkbox "Date Last Opened"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Date Added"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Size"
               if its value = 0 then
                  click it
               end if
            end tell
            tell checkbox "Kind"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Version"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Comments"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Tags"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Use relative dates"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Calculate all sizes"
               if its value = 1 then
                  click it
               end if
            end tell
            tell checkbox "Show icon preview"
               if its value = 1 then
                  click it
               end if
            end tell
            
         end tell
         
      end tell
      
      # keystroke "j" using command down -- depreated.
      
      --» Hide View Options for Finder Window
      tell menu bar 1
         tell menu bar item "View"
            tell menu 1
               tell menu item "Hide View Options"
                  perform action "AXPress"
               end tell
            end tell
         end tell
      end tell
      
   end tell
end tell

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on setFrontFinderWindowToListView()
   tell application "Finder"
      tell front Finder window
         set its current view to list view
      end tell
   end tell
end setFrontFinderWindowToListView
--------------------------------------------------------
on setFrontFinderWindowToIconView()
   tell application "Finder"
      tell front Finder window
         set its current view to icon view
      end tell
   end tell
end setFrontFinderWindowToIconView
--------------------------------------------------------

(*

CHANGE LIST

   2021/07/07 13:14
      + Adjusted for Mojave.

   2021/11/12 10:53
      + Deprecated keystroke dismissal of View Options for menu command.

*)

--------------------------------------------------------
1 Like

Oh wow, you know I never bothered looking in the view menu. Some handy shortcuts in there, though not enough.

Your AppleScript looks really promising! Thanks for sharing that. I see what you're doing!

Silly question: I'm trying to edit and save as an external file (.scpt?) but BBEdit isn't colour coding it and it's hard to read in monotone. Script Editor showing the same. Does it need an opening piece of code or something?

Edit: ignore that, sorted it. Gonna give it a whizz

1 Like

I managed to get the basics of it working, but I'm stuck at the Icon Size slider.

I'm curious about some of the conditionals you've got. For example

tell group 1
   if (exists of checkbox "Date Modified") = false then
      setFrontFinderWindowToIconView() of me
      delay 0.15
      setFrontFinderWindowToListView() of me
      delay 0.15
   end if
end tell

I actually commented all of that out and just called the setFrontFinderWindowToIconView() directly. But there's prob a reason why you're doing this double call (first set to Icon then set to List, in the same process).

But regardless, I also removed all of the tickbox triggers you had since I don't need them. The main things I'd like to control are:

  • view type: [icon | list | column]
  • grouping: [none | by kind]
  • order: [by date mod | by name]
    I've got this working so far!

But I'm stuck at the icon size (for icon-view only), which I'd like to control like this:

  • Icon size [16x16 | 48x48]
  • Grid spacing [0% | 100%]
  • Label position [Bottom | Right]

In searching for solutions, I came across this:

tell application "Finder"
   set thisFolder to target of front Finder window
   set the current view of front Finder window to icon view
   set icon size of icon view options of front Finder window to 256
   set arrangement of icon view options of front Finder window to arranged by name
   close front Finder window
   open thisFolder
end tell

Which is a lot more simplistic than your code. Wondering if this is the deprecated stuff you were talking about?

I also found the set slider command, but don't know how to use it.

With all that said, it's starting to get a bit much for me to get my head around and unfortunately I just can't commit to more than one or two sessions to get something like this working. Once it gets fiddly like this, I need to drop it and move on.

I'd be willing to pay someone to make it for me though! :slight_smile:

Ideally would have the presets working with a midi controller.