I got on a roll and made the corollaries to this handler and a proper set of tests.
on FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)
--https://www.macscripter.net/t/filesystem-convert-objects-to-nsurls/78025/
script acceleratorScript -- Script object holding a list for faster access to the list's items.
property fastAccessList : (fileSystemObjectList as list)'s items -- Single item as list or list from NSArray or new list with another's items.
end script
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
try
--RETURN ANY SINGULAR NSURL ARGUMENT
if (fileSystemObjectList's class is in {class "NSURL"}) then return fileSystemObjectList
end try
try
--RETURN ANY NSARRAY OF NSURLS ARGUMENT
set trialArray to current application's NSArray's arrayWithArray:(acceleratorScript's fastAccessList)
set classSet to current application's NSMutableSet's setWithArray:(trialArray's valueForKey:("className"))
set filter to current application's NSPredicate's predicateWithFormat:("! self CONTAINS 'NSURL'")
classSet's filterUsingPredicate:(filter)
if (classSet's |count|() = 0) then
if singularParameter then return item 1 of trialArray
return trialArray
end if
on error
--NSARRAY CONTAINS NON NSURLS (Errors with lists containing System Events stuff.)
end try
--CONVERT OBJECTS
repeat with thisObjectReference in (a reference to acceleratorScript's fastAccessList)
set thisObjectContents to thisObjectReference's contents
if (thisObjectContents's class is in {«class furl», alias, «class fsrf», class "NSURL"}) then --DO NOTHING
else
try
set theString to (thisObjectContents as {text, POSIX file})
if (theString's class is «class furl») then
set thisObjectReference's contents to (POSIX file (thisObjectContents's URL)) -- Assumed System Events file or folder
else
if ((theString starts with "/") or (theString starts with "file:///")) then
set thisObjectReference's contents to (POSIX file theString) -- full POSIX path or Finder URL
else
if (theString starts with "~") then
set thisObjectReference's contents to (current application's NSURL's fileURLWithPath:((current application's NSString's stringWithString:theString)'s |stringByExpandingTildeInPath|())) -- abreviated POSIX path
else
set thisObjectReference's contents to (theString as «class furl») -- HFS path
end if
end if
end if
on error
set thisObjectReference's contents to (POSIX file (thisObjectContents's URL)) -- Assumed System Events disk or file reference
end try
end if
end repeat
if singularParameter then return (current application's NSArray's arrayWithArray:(acceleratorScript's fastAccessList))'s objectAtIndex:(0)
return current application's NSArray's arrayWithArray:(acceleratorScript's fastAccessList)
end FileSystem_Convert_Objects_To_NSURLS
.
.
on FileSystem_Convert_Objects_To_PosixPaths(fileSystemObjectList)
try
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
--CONVERT OBJECTS
set nsurlArray to FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)
set PosixPathList to (nsurlArray's valueForKey:"path") as list
if singularParameter then return item 1 of PosixPathList
return PosixPathList
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_PosixPaths>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_PosixPaths
.
.
on FileSystem_Convert_Objects_To_PosixFiles(fileSystemObjectList)
try
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
--CONVERT OBJECTS
set NSURLList to FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)
set fileObjectList to NSURLList as list --COERCES NSURLS TO FILE REFERENCES
if singularParameter then return item 1 of (fileObjectList as list)
return fileObjectList
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_PosixFiles>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_PosixFiles
.
.
on FileSystem_Convert_Objects_To_Aliases(fileSystemObjectList)
try
script acceleratorScript -- Script object holding a list for faster access to the list's items.
property fastAccessList : (fileSystemObjectList as list)'s items -- Single item as list or list from NSArray or new list with another's items.
end script
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
repeat with thisObjectReference in (a reference to acceleratorScript's fastAccessList)
try
set thisObjectReference's contents to ((thisObjectReference's contents) as alias)
on error
try
set thisObjectReference's contents to (POSIX file (thisObjectReference's contents)) as alias
on error
try
set thisObjectReferencePath to thisObjectReference's contents
set thisObjectReferencePath to (current application's NSString's stringWithString:(thisObjectReferencePath))
set thisObjectReferencePath to (thisObjectReferencePath's stringByExpandingTildeInPath()) as text
set thisObjectReference's contents to (POSIX file (thisObjectReferencePath)) as alias
on error
beep
end try
end try
end try
end repeat
if singularParameter then return item 1 of (acceleratorScript's fastAccessList)
return (acceleratorScript's fastAccessList)
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_Aliases>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_Aliases
.
.
on FileSystem_Convert_Objects_To_HFSPaths(fileSystemObjectList)
try
script acceleratorScript -- Script object holding a list for faster access to the list's items.
property fastAccessList : (fileSystemObjectList as list)'s items -- Single item as list or list from NSArray or new list with another's items.
end script
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
repeat with thisObjectReference in (a reference to acceleratorScript's fastAccessList)
set thisObjectPath to ((thisObjectReference's contents) as text)
if thisObjectPath begins with "~" then
try
set thisObjectReferencePath to thisObjectReference's contents
set thisObjectReferencePath to (current application's NSString's stringWithString:(thisObjectReferencePath))
set thisObjectReferencePath to (thisObjectReferencePath's stringByExpandingTildeInPath()) as text
set thisObjectReference's contents to (POSIX file (thisObjectReferencePath)) as alias
on error
beep
end try
else
if thisObjectPath begins with "/" then
try
set thisObjectReferencePath to thisObjectReference's contents
set thisObjectReference's contents to (POSIX file (thisObjectReferencePath)) as alias
on error
beep
end try
end if
end if
set thisObjectReference's contents to ((thisObjectReference's contents) as text)
end repeat
if singularParameter then return item 1 of (acceleratorScript's fastAccessList)
return (acceleratorScript's fastAccessList)
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_Files>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_HFSPaths
.
This is the test suite. This script contains all the code above.
.
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "GameKit"
--Timing stuff
property reportText : ""
property startTime : missing value
property currentTime : missing value
--Provide a target folder to scan for files to list.
set targetFolder to path to home folder from user domain
set objectCount to 100
--Start a timer
set startTime to (current application's NSDate's new())
set currentTime to startTime
--List the folder, limiting the list to objectCount items.
set fileSystemObjectList to FileSystem_Generate_Comprehensive_FileSystemObjectList(targetFolder, objectCount)
report("FileSystem_Generate_Comprehensive_FileSystemObjectList(targetFolder, objectCount)" & linefeed & linefeed & "Lists the entire contents of the targetfolder, randomizes the list, truncates the list at objectCount (" & objectCount & ") items." & linefeed & "For each item randomly chooses from it's alias, posix path, fileURL, HFS path, or tilde abreviated path." & linefeed & linefeed)
--Start a timer for the conversions
set startTime to (current application's NSDate's new())
set currentTime to startTime
--Single parameter
repeat (objectCount / 5) times --objectCount total calls to these five handlers.
set NSURLItem to FileSystem_Convert_Objects_To_NSURLS(item 1 of fileSystemObjectList)
set PosixPathItem to FileSystem_Convert_Objects_To_PosixPaths(item 1 of fileSystemObjectList)
set PosixFileItem to FileSystem_Convert_Objects_To_PosixFiles(item 1 of fileSystemObjectList)
set AliasItem to FileSystem_Convert_Objects_To_Aliases(item 1 of fileSystemObjectList)
set HFSPathItem to FileSystem_Convert_Objects_To_HFSPaths(item 1 of fileSystemObjectList)
end repeat
report(linefeed & "Conversions:" & linefeed & linefeed & "All five Conversions with single parameters " & objectCount & " total calls.")
--List parameters
set NSURLList to FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)
set PosixPathList to FileSystem_Convert_Objects_To_PosixPaths(fileSystemObjectList)
set PosixFileList to FileSystem_Convert_Objects_To_PosixFiles(fileSystemObjectList)
set AliasList to FileSystem_Convert_Objects_To_Aliases(fileSystemObjectList)
set HFSPathList to FileSystem_Convert_Objects_To_HFSPaths(fileSystemObjectList)
report("All five Conversions with " & objectCount & " random object types each. ")
--A list of every supported file type converted to NSURL
FileSystem_Convert_Objects_To_NSURLS(NSURLList)
FileSystem_Convert_Objects_To_NSURLS(PosixPathList)
FileSystem_Convert_Objects_To_NSURLS(PosixFileList)
FileSystem_Convert_Objects_To_NSURLS(AliasList)
FileSystem_Convert_Objects_To_NSURLS(HFSPathList)
report(linefeed & "FileSystem_Convert_Objects_To_NSURLS " & " with " & objectCount & " objects of each type.")
--A list of every supported file type converted to PosixPaths
FileSystem_Convert_Objects_To_PosixPaths(NSURLList)
FileSystem_Convert_Objects_To_PosixPaths(PosixPathList)
FileSystem_Convert_Objects_To_PosixPaths(PosixFileList)
FileSystem_Convert_Objects_To_PosixPaths(AliasList)
FileSystem_Convert_Objects_To_PosixPaths(HFSPathList)
report("FileSystem_Convert_Objects_To_PosixPaths" & " with " & objectCount & " objects of each type.")
--A list of every supported file type converted to PosixFiles
FileSystem_Convert_Objects_To_PosixFiles(NSURLList)
FileSystem_Convert_Objects_To_PosixFiles(PosixPathList)
FileSystem_Convert_Objects_To_PosixFiles(PosixFileList)
FileSystem_Convert_Objects_To_PosixFiles(AliasList)
FileSystem_Convert_Objects_To_PosixFiles(HFSPathList)
report("FileSystem_Convert_Objects_To_PosixFiles " & " with " & objectCount & " objects of each type.")
--A list of every supported file type converted to Aliases
FileSystem_Convert_Objects_To_Aliases(NSURLList)
FileSystem_Convert_Objects_To_Aliases(PosixPathList)
FileSystem_Convert_Objects_To_Aliases(PosixFileList)
FileSystem_Convert_Objects_To_Aliases(AliasList)
FileSystem_Convert_Objects_To_Aliases(HFSPathList)
report("FileSystem_Convert_Objects_To_Aliases " & " with " & objectCount & " objects of each type.")
--A list of every supported file type converted to HFSPaths
FileSystem_Convert_Objects_To_HFSPaths(NSURLList)
FileSystem_Convert_Objects_To_HFSPaths(PosixPathList)
FileSystem_Convert_Objects_To_HFSPaths(PosixFileList)
FileSystem_Convert_Objects_To_HFSPaths(AliasList)
FileSystem_Convert_Objects_To_HFSPaths(HFSPathList)
report("FileSystem_Convert_Objects_To_HFSPaths " & " with " & objectCount & " objects of each type.")
--Report timing information
report(true) & linefeed & "Total Time " & ((current application's NSDate's new())'s timeIntervalSinceDate:startTime) & " seconds for " & ((objectCount) + (5 * objectCount) + (25 * objectCount)) & " total conversions."
on FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)
--https://www.macscripter.net/t/filesystem-convert-objects-to-nsurls/78025/
script acceleratorScript -- Script object holding a list for faster access to the list's items.
property fastAccessList : (fileSystemObjectList as list)'s items -- Single item as list or list from NSArray or new list with another's items.
end script
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
try
--RETURN ANY SINGULAR NSURL ARGUMENT
if (fileSystemObjectList's class is in {class "NSURL"}) then return fileSystemObjectList
end try
try
--RETURN ANY NSARRAY OF NSURLS ARGUMENT
set trialArray to current application's NSArray's arrayWithArray:(acceleratorScript's fastAccessList)
set classSet to current application's NSMutableSet's setWithArray:(trialArray's valueForKey:("className"))
set filter to current application's NSPredicate's predicateWithFormat:("! self CONTAINS 'NSURL'")
classSet's filterUsingPredicate:(filter)
if (classSet's |count|() = 0) then
if singularParameter then return item 1 of trialArray
return trialArray
end if
on error
--NSARRAY CONTAINS NON NSURLS (Errors with lists containing System Events stuff.)
end try
--CONVERT OBJECTS
repeat with thisObjectReference in (a reference to acceleratorScript's fastAccessList)
set thisObjectContents to thisObjectReference's contents
if (thisObjectContents's class is in {«class furl», alias, «class fsrf», class "NSURL"}) then --DO NOTHING
else
try
set theString to (thisObjectContents as {text, POSIX file})
if (theString's class is «class furl») then
set thisObjectReference's contents to (POSIX file (thisObjectContents's URL)) -- Assumed System Events file or folder
else
if ((theString starts with "/") or (theString starts with "file:///")) then
set thisObjectReference's contents to (POSIX file theString) -- full POSIX path or Finder URL
else
if (theString starts with "~") then
set thisObjectReference's contents to (current application's NSURL's fileURLWithPath:((current application's NSString's stringWithString:theString)'s |stringByExpandingTildeInPath|())) -- abreviated POSIX path
else
set thisObjectReference's contents to (theString as «class furl») -- HFS path
end if
end if
end if
on error
set thisObjectReference's contents to (POSIX file (thisObjectContents's URL)) -- Assumed System Events disk or file reference
end try
end if
end repeat
if singularParameter then return (current application's NSArray's arrayWithArray:(acceleratorScript's fastAccessList))'s objectAtIndex:(0)
return current application's NSArray's arrayWithArray:(acceleratorScript's fastAccessList)
end FileSystem_Convert_Objects_To_NSURLS
on FileSystem_Convert_Objects_To_PosixPaths(fileSystemObjectList)
try
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
--CONVERT OBJECTS
set nsurlArray to FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)
set PosixPathList to (nsurlArray's valueForKey:"path") as list
if singularParameter then return item 1 of PosixPathList
return PosixPathList
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_PosixPaths>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_PosixPaths
on FileSystem_Convert_Objects_To_PosixFiles(fileSystemObjectList)
try
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
--CONVERT OBJECTS
set NSURLList to FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)
set fileObjectList to NSURLList as list --COERCES NSURLS TO FILE REFERENCES
if singularParameter then return item 1 of (fileObjectList as list)
return fileObjectList
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_PosixFiles>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_PosixFiles
on FileSystem_Convert_Objects_To_Aliases(fileSystemObjectList)
try
script acceleratorScript -- Script object holding a list for faster access to the list's items.
property fastAccessList : (fileSystemObjectList as list)'s items -- Single item as list or list from NSArray or new list with another's items.
end script
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
repeat with thisObjectReference in (a reference to acceleratorScript's fastAccessList)
try
set thisObjectReference's contents to ((thisObjectReference's contents) as alias)
on error
try
set thisObjectReference's contents to (POSIX file (thisObjectReference's contents)) as alias
on error
try
set thisObjectReferencePath to thisObjectReference's contents
set thisObjectReferencePath to (current application's NSString's stringWithString:(thisObjectReferencePath))
set thisObjectReferencePath to (thisObjectReferencePath's stringByExpandingTildeInPath()) as text
set thisObjectReference's contents to (POSIX file (thisObjectReferencePath)) as alias
on error
beep
end try
end try
end try
end repeat
if singularParameter then return item 1 of (acceleratorScript's fastAccessList)
return (acceleratorScript's fastAccessList)
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_Aliases>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_Aliases
on FileSystem_Convert_Objects_To_HFSPaths(fileSystemObjectList)
try
script acceleratorScript -- Script object holding a list for faster access to the list's items.
property fastAccessList : (fileSystemObjectList as list)'s items -- Single item as list or list from NSArray or new list with another's items.
end script
set singularParameter to true --DETERMINE IF THE PARAMETER IS SINGULAR OR PLURAL
if ((fileSystemObjectList's class) is in {list}) then set singularParameter to false
tell current application's NSArray to if (its arrayWithArray:{fileSystemObjectList})'s firstObject()'s isKindOfClass:(it) then set singularParameter to false
repeat with thisObjectReference in (a reference to acceleratorScript's fastAccessList)
set thisObjectPath to ((thisObjectReference's contents) as text)
if thisObjectPath begins with "~" then
try
set thisObjectReferencePath to thisObjectReference's contents
set thisObjectReferencePath to (current application's NSString's stringWithString:(thisObjectReferencePath))
set thisObjectReferencePath to (thisObjectReferencePath's stringByExpandingTildeInPath()) as text
set thisObjectReference's contents to (POSIX file (thisObjectReferencePath)) as alias
on error
beep
end try
else
if thisObjectPath begins with "/" then
try
set thisObjectReferencePath to thisObjectReference's contents
set thisObjectReference's contents to (POSIX file (thisObjectReferencePath)) as alias
on error
beep
end try
end if
end if
set thisObjectReference's contents to ((thisObjectReference's contents) as text)
end repeat
if singularParameter then return item 1 of (acceleratorScript's fastAccessList)
return (acceleratorScript's fastAccessList)
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Convert_Objects_To_Files>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Convert_Objects_To_HFSPaths
on FileSystem_Generate_Comprehensive_FileSystemObjectList(targetFolder, listLimit)
--GENERATE A RANDOMIZED SAMPLE OF THE ENTIRE CONTENTS OF THE targetFolder OF LENGTH listLimit
--Include aliases,posix paths, HFS paths, file references, «class fsrf», tilde paths, Finder references, system events file and disk references.
set NSURLList to FileSystem_List_Contents(targetFolder)
set tildePathsList to {}
set x to current application's (NSMutableArray's arrayWithArray:(NSURLList))
set NSURLList to x's shuffledArray()
set NSURLList to NSURLList's subarrayWithRange:{location:0, |length|:listLimit}
set randomObjectTypeList to {}
--Create all of the possible file system object types
--FINDER OBJECT REFERENCES
set folderObject to (path to home folder from user domain)
set HomeFolderFolderList to ((current application's NSFileManager's defaultManager's enumeratorAtURL:folderObject includingPropertiesForKeys:{} options:7 errorHandler:(missing value))'s allObjects())
set HomeFolderFolderNameList to FileSystem_Objects_Return_Names(HomeFolderFolderList)
set finderObjectList to {}
repeat with thisFolderNSURL in HomeFolderFolderNameList
try
tell application id "com.apple.finder" to set the end of finderObjectList to item 2 of (folder thisFolderNSURL of home)'s {URL, it}
end try
end repeat
--SYSTEM EVENTS OBJECT REFERENCES
tell application "System Events" to set SEObjectList to {home folder, documents folder, downloads folder, desktop folder, movies folder, music folder, pictures folder} --, startup disk
repeat with indx from 1 to ((NSURLList's valueForKeyPath:"@count.self") as integer)
--VARIOUS REFERENCE TYPES
set thisObjectNSURL to (NSURLList's objectAtIndex:(indx - 1))
try
set thisObjectAlias to (thisObjectNSURL as text) as alias
tell (thisObjectAlias) to set objectTypeList to {it, POSIX path, it as text, it as «class furl», it as «class fsrf»} --removed POSIX file POSIX path as it returns «class furl»
--Tilde abreviated path
set fullPath to (current application's NSString's stringWithString:(item 2 of objectTypeList))
set tildePath to (fullPath's stringByAbbreviatingWithTildeInPath())
set objectTypeList to objectTypeList & tildePath
--CHOOSE ONE TYPE TO REPRESENT THIS FILESYSTEM OBJECT
set the end of randomObjectTypeList to some item of objectTypeList
--CHOOSE ONE FINDER REFERENCE every 10 items
--if ((round (indx / 10)) * 10) = indx then set the end of randomObjectTypeList to some item of finderObjectList
--CHOOSE ONE SYSTEM EVENTS REFERENCE every 7 items
--if ((round (indx / 7)) * 7) = indx then set the end of randomObjectTypeList to some item of SEObjectList
on error
set the end of randomObjectTypeList to thisObjectAlias
end try
end repeat
return randomObjectTypeList
end FileSystem_Generate_Comprehensive_FileSystemObjectList
on FileSystem_List_Contents(folderObject)
--FULL RECURSIVE LISTING NOT INCLUDING INVISIBLES OR CONTENTS OF PACKAGES
try
set folderObject to FileSystem_Convert_Objects_To_NSURLS(folderObject)
set theEntireContents to ((current application's NSFileManager's defaultManager's enumeratorAtURL:folderObject includingPropertiesForKeys:{} options:6 errorHandler:(missing value))'s allObjects())'s mutableCopy()
return theEntireContents
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_List_Contents>" & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_List_Contents
on FileSystem_Objects_Return_Names(fileSystemObjectList)
--https://www.macscripter.net/u/Nigel_Garvey https://www.macscripter.net/t/return-nsarray-of-nsurls-filenames-without-extensions/77124/4
try
if (fileSystemObjectList's isKindOfClass:(current application's NSArray)) or (class of fileSystemObjectList is list) then
set nsurlArray to (current application's NSMutableArray's arrayWithArray:(FileSystem_Convert_Objects_To_NSURLS(fileSystemObjectList)))
set nsurlArray to ((((nsurlArray's valueForKeyPath:"URLByDeletingPathExtension.lastPathComponent")'s componentsJoinedByString:(character id 0))'s stringByReplacingOccurrencesOfString:":" withString:"/")'s componentsSeparatedByString:(character id 0)) as list
return nsurlArray
else --single object parameter
--return ((((fileSystemObjectList's valueForKeyPath:"URLByDeletingPathExtension.lastPathComponent")'s componentsJoinedByString:(character id 0))'s stringByReplacingOccurrencesOfString:":" withString:"/")'s componentsSeparatedByString:(character id 0))
return (fileSystemObjectList's valueForKeyPath:"URLByDeletingPathExtension.lastPathComponent")
end if
on error errorText number errornumber partial result errorResults from errorObject to errorExpectedType
error "<FileSystem_Objects_Return_Names>" & space & errorText number errornumber partial result errorResults from errorObject to errorExpectedType
end try
end FileSystem_Objects_Return_Names
on report(textDescription)
if textDescription is true then return reportText
set reportText to reportText & textDescription & " " & ((current application's NSDate's new())'s timeIntervalSinceDate:currentTime) & " seconds" & linefeed
set currentTime to (current application's NSDate's new())
end report