Reputation: 778
How can I have multiple files selected in Finder as if I chosen them with ctrl-click? I have tried open -R file1 file2
, but only the last one gets selected.
Upvotes: 2
Views: 1396
Reputation: 6092
set F to {POSIX file "/Path/To/File.1", POSIX file "/Path/To/File.2", POSIX file "/Path/To/File.3", ...}
tell application "Finder" to set selection to F
To work as you would expect, all the files ought to be in the same directory/folder. However, even if they aren't, Finder does appear to highlight them all with selection rectangles, and you can perform actions on these disparately located files, such as tell app "Finder" to move selection to NewFolder
. However, I've found it's not always consistent in deciding whether all of the files are part of the selection and the move, or just the last one in the list, or none of them at all. The behaviour appears unreliable, to say the least.
However, for files in the same directory—as if you were selecting them by hand with the mouse—it should work as you would expect.
If your list specifies a file that does not exist, the script will throw an error at the point Finder tries to set the selection.
So, perhaps a cleaner/safer way to pick multiple selections, might be like this:
set ActiveFolder to POSIX file "/Path/To/Some/Folder"
tell application "Finder"
set F to items of folder ActiveFolder whose name is in ¬
{"the_basename_of_file_one_plus_its.ext", ¬
"the_filename_of_the_second.ext", ¬
"this_is_the_third_one.ext", ... }
reveal F
end tell
Upvotes: 3