If since Snow Leopard and before Mavericks then you may be hitting the infamous Finder Selection bug.
Appears you are 100% correct. I had never encountered the bug before. Definitive fix is to upgrade my OS, but that's impossible for now. Searching, I noticed a fix (I think it was yours) suggesting opening and closing a new Finder window - And that appears to work with this script.
______________________________________________________________________
Hey James,
The Finder-Selection bug appeared in Lion and was finally squashed in Mavericks.
Opening a new window was the first solution I found, and it works but is a rather disruptive solution.
After a lot of experimentation I finally settled on a less intrusive option - switching out of the Finder and back to set the selection properly.
Since I run nearly all of my scripts from FastScripts my solution is generally this (pre Mavericks):
---------------------------------------- tell application "FastScripts" to activate tell application "Finder" activate set _sel to selection as alias list end tell if _sel ≠ {} then # Continue end if ----------------------------------------
Using something that's already running is of course the fastest solution, and a good alternative that doesn't depend upon 3rd party software is:
---------------------------------------- tell application "SystemUIServer" to activate ----------------------------------------
This causes the Finder to "blink", but you don't have that intrusive window flying around.
I used System Events for a while, but I found it would quit when unused for a while - and restarting the app could sometimes put very noticeable pauses in my scripts. I finally settled on the SystemUIServer which is always running, until it occurred to me that I was running from FastScripts anyway and might as well use that.
Occasionally I run AppleScripts from Keyboard Maestro, and when appropriate I've used the Keyboard Maestro engine for my work-around.
Keyboard Maestro 6 has a specific option to work around this very nasty bug when using its own actions that work with the Finder-Selection.
-- Best Regards, Chris
------------------------------- Tags: @Finder, @Selection, @Bug -------------------------------
|