Check if folder is loaded
Hi All,
Had a need to test if a folder is fully loaded and came up with this would love to get any feedback.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set {folderCheck, finderCount, captureCount} to checkFolderHasLoaded()
if folderCheck is true then
display dialog "Folder loaded " & captureCount & " of " & finderCount & " images loaded."
end if
on checkFolderHasLoaded()
tell application "Capture One 23"
if current document's kind is session then
set theFolder to POSIX path of (get folder of current collection of current document)
set countA to my listFilesNotAliasesOrSymlinksIn(theFolder)
set countB to count of variants of current collection of current document
repeat while countA ≠ countB
delay 1
set countB to count of variants of current collection of current document
end repeat
return {true, countA, countB}
else
display dialog "Please Open a Session"
end if
end tell
end checkFolderHasLoaded
on listFilesNotAliasesOrSymlinksIn(sourceFolder)
set regKey to current application's NSURLIsRegularFileKey
set packageKey to current application's NSURLIsPackageKey
set aliasKey to current application's NSURLIsAliasFileKey
set pathKey to current application's NSURLPathKey
set fileManager to current application's NSFileManager's defaultManager()
set aURL to current application's |NSURL|'s fileURLWithPath:sourceFolder
set reqKeys to current application's NSArray's arrayWithArray:{regKey, packageKey, aliasKey, pathKey}
set theURLs to fileManager's contentsOfDirectoryAtURL:aURL includingPropertiesForKeys:reqKeys options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)
set theResults to current application's NSMutableArray's array() -- to hold result
repeat with aURL in theURLs
set {theValues, theError} to (aURL's resourceValuesForKeys:reqKeys |error|:(reference))
(theResults's addObject:theValues)
end repeat
set thePred to current application's NSPredicate's predicateWithFormat:" (%K == YES AND %K == NO) OR %K == YES" argumentArray:{regKey, aliasKey, packageKey}
theResults's filterUsingPredicate:thePred
return ((count of ((theResults's valueForKey:pathKey))) as list) as integer
end listFilesNotAliasesOrSymlinksIn
0
-
Have you tried asking Finder to get the files?
tell application "Finder"
set theFiles to (get every item of folder theFolder where ((kind is not "Alias") and (kind is not "Folder")))
set theCount to (count of theFiles)
end tell0 -
Yeah I find interacting with finder can trigger security/privacy warning dialogs. I’ve since replaced the line using the library with pure AObjC. Seems to work, but I wonder if there is a better was to check if a folder or collection has loaded. Thanks for taking a look.
0
Please sign in to leave a comment.
Comments
2 comments