In the process of learning the class NSFileWrapper and the instance property fileAttributes.
I made a script to compare 2 files and used NSFileSize property.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set theInputFile to POSIX path of (path to desktop) & "inputFile.txt"
set theCompareFile to POSIX path of (path to desktop) & "compareFile.txt"
my compareFilesBySize:theInputFile compareFileURL:theCompareFile
on compareFilesBySize:inputFileURL compareFileURL:inputCompareURL
set theInputURL to current application's |NSURL|'s fileURLWithPath:inputFileURL
set theCompareURL to current application's |NSURL|'s fileURLWithPath:inputCompareURL
set {theInputFile, theInputError} to current application's NSFileWrapper's alloc()'s initWithURL:theInputURL options:0 |error|:(reference)
set {theCompareFile, theCompareError} to current application's NSFileWrapper's alloc()'s initWithURL:theCompareURL options:0 |error|:(reference)
-- Check if the error message is missing value
if ((theInputError is not missing value) or (theCompareError is not missing value)) then return "Couldn't find the files"
set {theInputAttributes, theCompareAttributes} to {theInputFile's fileAttributes(), theCompareFile's fileAttributes()}
if ((NSFileSize of theInputAttributes)'s isEqual:(NSFileSize of theCompareAttributes)) as boolean then
display dialog "Files are equal in size"
else
display dialog "Files are not equal in size"
end if
end compareFilesBySize:compareFileURL:
After input from Shane I made a other one to use the class NSURL instead.
It use Instance Method resourceValuesForKeys: and NSURLResourceKey:NSURLFileSizeKey
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set theInputFile to POSIX path of (path to desktop) & "inputFile.txt"
set theCompareFile to POSIX path of (path to desktop) & "compareFile.txt"
my compareFilesBySize:theInputFile compareFileURL:theCompareFile
on compareFilesBySize:inputFileURL compareFileURL:inputCompareURL
set theInputURL to current application's |NSURL|'s fileURLWithPath:inputFileURL
set {inputFile, inputError} to theInputURL's resourceValuesForKeys:{"NSURLFileSizeKey"} |error|:(reference)
set theCompareURL to current application's |NSURL|'s fileURLWithPath:inputCompareURL
set {compareFile, compareError} to theCompareURL's resourceValuesForKeys:{"NSURLFileSizeKey"} |error|:(reference)
if ((inputError is not missing value) or (compareError is not missing value)) then return "Couldn't find the files"
if ((inputFile)'s isEqual:(compareFile)) as boolean then
display dialog "Files are equal in size"
else
display dialog "Files are not equal in size"
end if
end compareFilesBySize:compareFileURL: