Trigger on change in finder selection?

Hey Chris

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! :slight_smile:

(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

etc, etc.

1 Like