Apple Script - Recursive Function
Hello there!
So, I'm struggling to code a recursive function that would go through every possible sub-folder, sub-sub-folder and so on of a parent folder (the one that's opened in the foreground), but I came to a point where the script gets an error message when it tries to make the recursion.
I suppose that this error is due to the class scope, but to be honest I don't know how to fix this issue.
Here's my apple script.
on openFolders(folderName)
tell application "Finder"
set theWindow to window 1
set folderCount to count of folders of theWindow
if folderCount is 0 then
return
end if
set allFolders to every folder of theWindow
repeat with i from 1 to folderCount - 1
openFolders(item i in allFolders)
delay 1 -- Optional delay to wait for the folder to open
end repeat
set target of theWindow to item folderCount in allFolders
openFolders(item folderCount in allFolders)
end tell
end openFolders
on run {input, parameters}
tell application "System Events" to tell process "Finder"
set frontmost to true
end tell
set theWindow to window 1
openFolders(theWindow)
return input
end run
P.S. I ended up doing apple scripts due to the fact that 'SetFolderViews' in Automator messes with the Finder backgrounds and now I'm trying to build an automation script that would revert the background of every folder to 'Default'. I'd be more than happy to share the final script with you and with everybody who needs it. Who knows, I might upload it to GitHub if I could get past this current issue.
Cheers,
Stefan-Daniel
MacBook Pro 13″, macOS 14.0