estockly
(Ed Stockly)
October 25, 2020, 7:32pm
#1
This causes SD to hang and it has to be restarted.
It doesn’t cause SE to hang, but it might as well. The script indicates it’s running, but it doesn’t time out and it can’t be stopped and it cmmd-. won’t trigger an error.
use AppleScript version "2.5"
use scripting additions
use script "FileManagerLib"
set appFolder to (path to "apps") --'s POSIX path & "CoreTypes.bundle/Contents/Resources/"
set appFileNames to objects of appFolder ¬
searching subfolders true ¬
include invisible items false ¬
include folders false ¬
include files true ¬
result type files list
estockly
(Ed Stockly)
October 25, 2020, 7:39pm
#2
After about 10 minutes SE let me stop the script
You’re just overwhelming AppleScript. You’re dealing with a list of probably tens of thousands of items, and AppleScript just doesn’t scale that well.
estockly
(Ed Stockly)
October 25, 2020, 10:49pm
#4
That’s what I figured.
For this particular issue I’ve gotten a list of apps and folders, and I’m getting the files from each.
Should would be nice to have a command like this:
every file of entire contents of thisFolder whose name_extension is "icns"
estockly
(Ed Stockly)
October 25, 2020, 10:56pm
#5
This came up before, I’ll try this. (I think I was still on 10.10 then.)
This requires 10.11 or later, but should be pretty quick:
use AppleScript version "2.5" -- requirs 10.11 or later
use framework "Foundation"
use script "FileManagerLib" version "2.2.1"
use scripting additions
FilterEntireContents2("/Users/shane/Desktop")
on FilterEntireContents2(aFolder)
set folderContents to objects of aFolder ¬
searching subfolders true ¬
include invisible items false ¬
include folders false ¬
include files true ¬
result type urls array
set thePred to current application's NSPredicate's predicateWithFormat:"pathExtension IN[c] %@" argumentArray:{{"wav", "band", "mp3", "m4p", "m4a"}}
return (folderContents's filteredArrayUsingPredicate:thePred) as list
end FilterEntireContents2
But you can make it significantly faster by changing include folders
to true. Assuming you don’t use extensions for folder names, the result will be the same. But importantly, when both include folders
and include files
are true, no time is spent separating folders from files and packages — and that’s what takes most of the time because it requires a repeat loop. I’m talking a factor of more than x10.