• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Finder window views ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finder window views ?


  • Subject: Re: Finder window views ?
  • From: Christopher Stone <email@hidden>
  • Date: Wed, 22 Feb 2017 17:36:58 -0600

On Feb 22, 2017, at 16:55, Jean-Christophe Helary <email@hidden> wrote:
I'm kind of tired of having to arrange the windows one by one so I was thinking of writing a script that would remove or add view items, change the sort order etc. at once. So that every time I meet a non conformant window, I just change it on the spot...


Hey Jean-Christophe,

Finder-view scripting is a bit problematic to the consternation (profanity elided) of many Mac scripters.

Some things work, and some things don't.

Some things only work after you refresh a window.

To add and remove elements to a window you'll have to use GUI-Scripting as in script 1 below.

If my memory serves it used to be possible to do something like set visible of column size column to true/false for some columns but not all – but this was broken back around Mountain Lion.

For more examples see script 2.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------

Script 1

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/01 13:04
# dMod: 2016/08/27 15:54
# Appl: System Events
# Task: Set List View Attributes
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Set, @List-View, @Attributes
-------------------------------------------------------------------------------------------

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

         

         keystroke "j" using command down

         

         set theClock to 0

         

         repeat while front window's subrole is not "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 "Arrange 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 = 1 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 = 0 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

         

         keystroke "j" using command down

         

      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
-------------------------------------------------------------------------------------------

Script 2

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2010/10/09 12:45
# dMod: 2017/02/20 05:11
# Appl: Finder
# Task: Resize front window to large default size.
#     : Special-Filters for various windows.
# Libs: None
# Tags: @Applescript, @Finder, @Resize, @Window, @Filter
-------------------------------------------------------------------------------------------
property defaultWindowBounds : {0, 23, 844, 1196}
property defaultSideBarWidth : 140
-------------------------------------------------------------------------------------------

try

   

   set kmWorkng to ((path to documents folder as text) & "Working Items (Current):Working ⇢ Keyboard Maestro:")
   set safariBookmarksRoot to ((path to documents folder as text) & "Bookmarks_Safari:")
   set sdScriptSnapShots to ((path to documents folder as text) & "Code_Projects:Script_Debugger:Script-Snap-Shots:")
   set webArchives to ((path to documents folder as text) & "Web Archives:")
   set workingItemsCurrent to ((path to documents folder as text) & "Working Items (Current):")

   

   tell application "Finder"
      if (count of windows) > 0 then

         

         tell front window

            

            set winTarget to (its target) as text

            

            if current view ≠ list view then
               set current view to list view
            end if

            

            if winTarget = kmWorkng then
               set bounds to {0, 23, 1040, 1196}

               

            else if winTarget = sdScriptSnapShots then
               --» Script Dumps folder.
               set bounds to {0, 23, 1075, 1196}

               

               tell its list view options
                  width of column id name column
                  set width of column id name column to 900
                  set width of column id modification date column to 141
                  set width of column id creation date column to 141
                  set width of column id modification date column to 141
                  set width of column id size column to 97
               end tell

               

            else if winTarget = workingItemsCurrent then
               --» Working Items folder.
               tell its list view options
                  set width of column id name column to 413
                  set width of column id modification date column to 141
                  set width of column id creation date column to 141
                  set width of column id modification date column to 141
                  set width of column id size column to 97
               end tell

               

               set bounds to {0, 23, 900, 1196}

               

            else if winTarget starts with safariBookmarksRoot then
               --» Safari Bookmarks folder.
               tell its list view options
                  set width of column id name column to 675
                  set width of column id creation date column to 181
               end tell

               

               set bounds to {0, 23, 1032, 1196}

               

            else if winTarget starts with webArchives then
               --» Web Archives folder.
               tell its list view options
                  set width of column id name column to 900
                  set width of column id creation date column to 181
               end tell

               

               set bounds to {437, 23, 1482, 1196}

               

            else
               --» Generic.
               tell its list view options
                  set width of column id name column to 413
                  set width of column id modification date column to 141
                  set width of column id size column to 97
               end tell

               

               set bounds to defaultWindowBounds

               

            end if

            

            if toolbar visible = false then set toolbar visible to true
            if statusbar visible = false then set statusbar visible to true
            if sidebar width ≠ 135 then set sidebar width to defaultSideBarWidth

            

         end tell

         

      end if

      

   end tell

   

on error errMsg number errNum
   beep
   tell me to display dialog "Error: " & errMsg & return & "Error Number: " & errNum
end try

-------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Finder window views ?
      • From: Robert Poland <email@hidden>
    • Re: Finder window views ?
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >Finder window views ? (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Finder window views ?
  • Next by Date: Re: [ANN] Table dialogs
  • Previous by thread: Finder window views ?
  • Next by thread: Re: Finder window views ?
  • Index(es):
    • Date
    • Thread