When I open a finder window (anything) and want to get a file name via a selection, I never get the right result the first time I execute my script. Only the second time. Any hints or tips?
This looks promising. First tests make me feel warm and fuzzy…Looks like I am getting more like expected behaviour. Will report back if it goes weird on me…
Still not woking right. If I select a document in a Finder window, then open new Finder window and select new documents, when I run script
tell application "Finder"
activate
set mywin to Finder window 1
set index of mywin to 1
set theSelection to selection
end tell
… it returns the selection in the background (original) Finder window. I was hoping your tweak would force the selection from the open frontmost Finder window.
If I click out of the newly created window then click back into it, the get selection works fine. Perhaps this action can be scripted or emulated to get around this bug…?
From Chris’s message: “The specific sequence you used to create the failure may or may not be reliably repeatable on Lion, but the bug exists nevertheless.” IOW, it’s intermittent.
Adam, I was not having luck with your suggestion. Opening a new window and selecting within it, then running the script, would return nil or the selection in background window.
Shane’s suggestion works for me, thanks (until further notice/testing):
tell application "SystemUIServer" to activate
tell application "Finder"
activate
set sel to selection as alias list
end tell
The window flashes very quickly as well which is a nice side effect of this script, as it gives immediate feedback that something is happening (I use Quicksilver to invoke the script - which sends the selected document(s) to my iPad via AirDoc Sender, a brilliant little app for transferring documents etc from Mac to iPad BTW).
You see, I really wondered how the open command worked, regarding how it do activate apps.
What SystemUIServer really do by becoming the foreground, is that it somehow forces Finder to refresh its internal datastructures.(Maybe it will work by activating any other app. I think the reason for using SystemUIServer is that it is such small, and easily available app.)
I was wondering if open would do the same, force a deactivation, then an activation of Finder.