Hi Peter & others
What would it take to get a trigger for "Finder Selection Changed" ? Of course this event occurs a lot! so I appreciate the overhead could be prohibitive.
Alternatively, I can poll Finder (with AppleScript) to track its selection. Again overhead - how heavy a load if I set that running in KM, say a few times / second?
the goal is to dynamically display info about the current finder's selection. to feel responsive, the display needs to track the selection within .2 - .4 seconds.
thank you!
thanks for your thoughts. after I posted, it occurred to me that KM's nearest comparison to that kind of monitoring is the trigger on change of clipboard.
I went with an AppleScript daemon (not in KM) polling every .5 second and I can't detect any lag on an MacBook air M1. FYI, code snippet is below.
this is for a project I described here which shows info about the finder selection in a custom floating html prompt. It's quite responsive, even deep querying info about image files. (adding a screen movie now). Maybe you underestimate MacOS's ability to keep up!
(1st time posting code here, is this ok?)
on idle -- watch for changes in finder selection
try
set allsel to application "Finder"'s selection
on error
set oldsel to {} --bail
return 0.5
end try
if allsel is not oldsel then -- selection has changed
getstats(allsel)
set oldsel to allsel
end if
return 0.5 -- did you need that cpu for anything important?
end idle
on getstats(selectedFiles)
set sizeString to ""
set picDimensions to ""
set compressionratio to ""
if length of selectedFiles > 1 then -- multiple items selected. compute total size.
set sumtotal to 0
repeat with aFile in selectedFiles