I have a number of scripts that generate an alias list, which is then submitted to an ASObjC handler for processing. There are often at least two approaches by which this can be done: the first is to explicitly convert the aliases to a POSIX path and then to a URL; the second is to let the scripting bridge handle the conversions.
To help determine if one approach is better than the other, I ran some timing tests. The results were:
Explicit Conversion: 0.510 second
Scripting-bridge conversion: 0.280 second
I’ve included the timing test below. I used the isUbiquitousItemAtURL method because I wanted something that returned a boolean and required a url. The script includes both of the code segments being tested and one has to be commented out to test the other. I’m new to ASObjC and if my testing methodology or understanding of this whole issue is faulty, please let me know.
use framework "Foundation"
use scripting additions
-- untimed code
set testFolder to (choose folder)
tell application "Finder"
set theFiles to every file of the entire contents of testFolder as alias list -- contains 443 files
end tell
-- start time
set startTime to current application's CFAbsoluteTimeGetCurrent()
-- timed code
-- explicit conversion
set fileManager to current application's NSFileManager's defaultManager()
repeat with aFile in theFiles
set thePath to (current application's |NSURL|'s fileURLWithPath:(POSIX path of aFile))
set theResult to (fileManager's isUbiquitousItemAtURL:thePath)
end repeat
-- scripting bridge
# set fileManager to current application's NSFileManager's defaultManager()
# repeat with aFile in theFiles
# set theResult to (fileManager's isUbiquitousItemAtURL:aFile)
# end repeat
-- elapsed time
set elapsedTime to (current application's CFAbsoluteTimeGetCurrent()) - startTime
set nf to current application's NSNumberFormatter's new()
nf's setFormat:("0.000")
set elapsedTime to ((nf's stringFromNumber:elapsedTime) as text) & " seconds"
-- result
elapsedTime