This got me thinking about the whole business of file information, and the 'info for' command that is at the heart of your script.
Anyway, here's a script library that returns quite a bit more info. It returns it either as a text version of a property list, or if you have ASObjCExtras.framework installed, as a record. All it needs is someone like Chris to format the result nicely...
use framework "Foundation"
-- use framework "ASObjCExtras" ###### If you have ASObjCExtras.framework installed, uncomment this line
on moreInfoFor:POSIXPath dirSizes:sizeBoolean
-- get what we can from URL
set anNSURL to current application's NSURL's fileURLWithPath:POSIXPath
-- build list of keys for values we want
set valuesList to {current application's NSURLCreationDateKey, current application's NSURLContentModificationDateKey, current application's NSURLContentAccessDateKey, current application's NSURLNameKey, current application's NSURLFileSizeKey, current application's NSURLIsDirectoryKey, current application's NSURLIsAliasFileKey, current application's NSURLIsPackageKey, current application's NSURLIsHiddenKey, current application's NSURLHasHiddenExtensionKey, current application's NSURLLocalizedNameKey, current application's NSURLLocalizedTypeDescriptionKey, current application's NSURLTypeIdentifierKey, current application's NSURLIsWritableKey, current application's NSURLIsExcludedFromBackupKey, current application's NSURLIsExecutableKey, current application's NSURLIsSymbolicLinkKey, current application's NSURLLabelNumberKey, current application's NSURLLinkCountKey, current application's NSURLTagNamesKey, current application's NSURLFileAllocatedSizeKey, current application's NSURLTotalFileSizeKey, current application's NSURLTotalFileAllocatedSizeKey}
-- fetch values for our keys
set {attsNSDictionary, theError} to anNSURL's resourceValuesForKeys:valuesList |error|:(reference)
if attsNSDictionary is missing value then -- something went wrong, throw error
error (theError's localizedDescription() as text)
end if
-- make a mutable copy so we can modify values
set attsNSMutableDictionary to attsNSDictionary's mutableCopy()
-- handle tags: if there are none there will be no value, so we will put in an empty list
set theTags to (attsNSDictionary's valueForKey:(current application's NSURLTagNamesKey))
if theTags is missing value then
attsNSMutableDictionary's setObject:{} forKey:(current application's NSURLTagNamesKey)
end if
-- do stuff just for direcetories
if (attsNSDictionary's valueForKey:(current application's NSURLIsDirectoryKey)) then
set theNSBundle to current application's NSBundle's bundleWithURL:anNSURL
set bundleInfoNSDictionary to theNSBundle's infoDictionary()
attsNSMutableDictionary's addEntriesFromDictionary:bundleInfoNSDictionary
if sizeBoolean as boolean then
-- we need to get the total size of all items in the directory
set {s1, s2, s3, s4} to my fileSizeFor:anNSURL rawSize:0 allocatedSize:0 totalSize:0 totalAllocatedSize:0
attsNSMutableDictionary's setValue:s1 forKey:(current application's NSURLFileSizeKey)
attsNSMutableDictionary's setValue:s2 forKey:(current application's NSURLFileAllocatedSizeKey)
attsNSMutableDictionary's setValue:s3 forKey:(current application's NSURLTotalFileSizeKey)
attsNSMutableDictionary's setValue:s4 forKey:(current application's NSURLTotalFileAllocatedSizeKey)
end if
end if
-- get the Spotlight metadata
set theNSMetadataItem to current application's NSMetadataItem's alloc()'s initWithURL:anNSURL
set theAtts to theNSMetadataItem's attributes()
set theMetadata to theNSMetadataItem's valuesForAttributes:theAtts
attsNSMutableDictionary's addEntriesFromDictionary:{SpotlightData:theMetadata}
-- get some extended attributes. This is undocumented API so may be dodgy, but it seems OK for these two values...
set theNSFileManager to current application's NSFileManager's defaultManager()
set allAtts to theNSFileManager's attributesOfItemAtPath:POSIXPath |error|:(missing value)
set extendedAtts to allAtts's valueForKey:"NSFileExtendedAttributes"
if extendedAtts is not missing value then
set isQuarantined to extendedAtts's objectForKey:"com.apple.quarantine"
if isQuarantined is missing value then
attsNSMutableDictionary's setValue:false forKey:"isQuarantined"
else
attsNSMutableDictionary's setValue:true forKey:"isQuarantined"
end if
set textEncoding to extendedAtts's objectForKey:"com.apple.TextEncoding"
if textEncoding is not missing value then
set textEncoding to current application's NSString's alloc()'s initWithData:textEncoding encoding:(current application's NSUTF8StringEncoding)
attsNSMutableDictionary's setValue:textEncoding forKey:"textEncoding"
end if
end if
-- get the app that would open it
set theNSWorkspace to current application's NSWorkspace's sharedWorkspace()
set appURL to theNSWorkspace's URLForApplicationToOpenURL:anNSURL
attsNSMutableDictionary's setValue:appURL forKey:"defaultApplication"
###### If you have ASObjCExtras.framework installed, uncomment the following line
-- return (current application's SMSFord's fordIn:attsNSMutableDictionary) as record
return attsNSMutableDictionary's |description|() as text
end moreInfoFor:dirSizes:
on fileSizeFor:aURL rawSize:theSize allocatedSize:allocSize totalSize:totSize totalAllocatedSize:totalAllocSize
set theNSFileManager to current application's NSFileManager's defaultManager()
set valuesList to {current application's NSURLFileSizeKey, current application's NSURLFileAllocatedSizeKey, current application's NSURLTotalFileSizeKey, current application's NSURLTotalFileAllocatedSizeKey, current application's NSURLIsDirectoryKey}
set theFiles to (theNSFileManager's contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:valuesList options:0 |error|:(missing value)) as list
repeat with anNSURL in theFiles
set attsNSDictionary to (anNSURL's resourceValuesForKeys:valuesList |error|:(missing value))
if (attsNSDictionary's valueForKey:(current application's NSURLIsDirectoryKey)) as boolean then
set {theSize, allocSize, totSize, totalAllocSize} to (my fileSizeFor:anNSURL rawSize:theSize allocatedSize:allocSize totalSize:totSize totalAllocatedSize:totalAllocSize)
else
set theSize to (theSize as integer) + ((attsNSDictionary's valueForKey:(current application's NSURLFileSizeKey)) as integer)
set allocSize to (allocSize as integer) + ((attsNSDictionary's valueForKey:(current application's NSURLFileAllocatedSizeKey)) as integer)
set totSize to (totSize as integer) + ((attsNSDictionary's valueForKey:(current application's NSURLTotalFileSizeKey)) as integer)
set totalAllocSize to (totalAllocSize as integer) + ((attsNSDictionary's valueForKey:(current application's NSURLTotalFileAllocatedSizeKey)) as integer)
end if
end repeat
return {theSize, allocSize, totSize, totalAllocSize}
end fileSizeFor:rawSize:allocatedSize:totalSize:totalAllocatedSize: