You may try to use :
# Requires BridgePlus available for free at : https://www.macosxautomation.com/applescript/apps/BridgePlus.html
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
script o
property showOptions : ""
end script
set theFolder to (choose folder)
set PosixPath to POSIX path of theFolder
# Grab the localized version of the menu item "Afficher les options de présentation"
tell application "Finder" to set o's showOptions to localized string "N35"
(* List the folders of the selected one *)
set theResult to current application's SMSForder's foldersIn:PosixPath recursive:true skipHidden:true skipInsidePackages:true asPaths:false
set theFolders to theResult as list # une liste d' URLs
# Add the root folder to the list
set end of theFolders to theFolder
--return (count theFolders as text)
tell application "Finder"
repeat with aFolder in theFolders
open aFolder
try
set current view of window 1 to icon view
end try
my ruleSettings()
close window 1
end repeat
end tell
on ruleSettings()
tell application "System Events" to tell process "Finder"
set frontmost to true
if name of menu item 21 of menu 1 of menu bar item 5 of menu bar 1 = o's showOptions then
keystroke "j" using {command down} -- open Presentation settings window
repeat 10 times
if subrole of window 1 is "AXSystemFloatingWindow" then exit repeat
delay 0.1
end repeat
end if
tell window 1
(*
class of UI elements --> {checkbox, checkbox, static text, pop up button, pop up button, static text, group, button, button, static text}
role description of buttons --> {"bouton", "Bouton de fermeture"}
*)
tell pop up button 1
repeat 10 times
try
click it --> pop up button "Trier par :"
exit repeat
end try
delay 0.2
end repeat
-- name of menu items of menu 1
--> {"Aucun", missing value, "Aligner sur la grille", missing value, "Nom", "Type", "Date de dernière ouverture", "Date de l'ajout", "Date de modification", "Date de création", "Taille", "Tags"}
repeat 10 times # ran it upon a folder with 1 753 853 folders and never loop more than 5 times
try
set byName to name of menu item 5 of menu 1
exit repeat
end try
delay 0.2
end repeat
click menu item byName of menu 1 # "Nom"
end tell # pop up button 1
delay 0.2
tell pop up button 2
repeat 10 times
try
click it --> pop up button "Organiser par :".
exit repeat
end try
delay 0.2
end repeat
-- name of menu items of menu 1
--> {"Nom", "Type", "Application", "Date de dernière ouverture", "Date de l'ajout", "Date de modification", "Date de création", "Taille", "Tags", missing value, "Aucun"}
repeat 10 times # ran it upon a folder with 1 753 853 folders and never loop more than 5 times
try
set noneItem to name of menu item -1 of menu 1
exit repeat
end try
delay 0.2
end repeat
click menu item noneItem of menu 1 # "None"
end tell # pop up button 1
click button 2 # close the window
end tell
end tell
end ruleSettings
As the icon view options are defined as read only, I use GuiScripting.
Edited because when I ran it upon a folder with 1,753,853 subfolders the wanted menu item wasn’t available immediately. A loop with a try/ end try is now taking care of that. It wait from 0 to 2 seconds for the availability of the item. On the large folder used for tests, it loops 5 times only once.
Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) mercredi 30 novembre 2016 18:16:03