Hey Folks,
I managed to repurpose one of Shane's scripts to filter-out-by-extension rather than find-by-extension.
I needed this for a task today, and now I'm struggling with figuring out compound predicates.
In any case I thought I'd share. (The original is appended for convenience.)
------------------------------------------------------------------------------ # Auth: Christopher Stone { Heavy Lifting by Shane Stanley } # dCre: 2016/05/13 23:06 # dMod: 2017/02/26 23:45 # Appl: AppleScriptObjC # Task: List Files by Extension → Handler # Aojc: True # Libs: None # Osax: None # Tags: @Applescript, @Script, @List, @Files, @Extension, @File_Extension ------------------------------------------------------------------------------
use framework "Foundation" use framework "AppKit" use scripting additions
set sourceFolder to POSIX path of (path to desktop folder)
set textFiles to its filterOutFilesByExtension:{"txt", "scpt"} fromDirectory:sourceFolder
on filterOutFilesByExtension:listOfExtensions fromDirectory:sourceFolder set fileManager to current application's NSFileManager's defaultManager() set aURL to current application's |NSURL|'s fileURLWithPath:sourceFolder set directoryContents to fileManager's contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:0 |error|:(missing value) set foundItemList to current application's NSPredicate's predicateWithFormat_("NOT pathExtension.lowercaseString IN %@", listOfExtensions) set foundItemList to directoryContents's filteredArrayUsingPredicate:foundItemList
# Return as a list of as «class furl» return foundItemList as list
# Return as a list POSIX Paths # set foundItemList to (foundItemList's valueForKey:"path") as list # return foundItemList
end filterOutFilesByExtension:fromDirectory:
------------------------------------------------------------------------------
------------------------------------------------------------------------------ # Auth: Christopher Stone { Heavy Lifting by Shane Stanley } # dCre: 2016/05/13 23:06 # dMod: 2016/05/16 05:15 # Appl: AppleScriptObjC # Task: List Files by Extension → Handler # Aojc: True # Libs: None # Osax: None # Tags: @Applescript, @Script, @List, @Files, @Extension, @File_Extension ------------------------------------------------------------------------------
use framework "Foundation" use framework "AppKit" use scripting additions
set sourceFolder to POSIX path of (path to desktop folder)
set pdfFiles to its listFilesByExtension:{"txt"} fromDirectory:sourceFolder
on listFilesByExtension:listOfExtensions fromDirectory:sourceFolder set fileManager to current application's NSFileManager's defaultManager() set aURL to current application's |NSURL|'s fileURLWithPath:sourceFolder set directoryContents to fileManager's contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:{} options:0 |error|:(missing value) set foundItemList to current application's NSPredicate's predicateWithFormat_("pathExtension.lowercaseString IN %@", listOfExtensions) set foundItemList to directoryContents's filteredArrayUsingPredicate:foundItemList
# Return as a list of as «class furl» return foundItemList as list
# Return as a list POSIX Paths # set foundItemList to (foundItemList's valueForKey:"path") as list # return foundItemList
end listFilesByExtension:fromDirectory:
------------------------------------------------------------------------------
|