Hi. One can select and open multiple files like so:
property thePath : "Macintosh HD:AppleScripts:"
tell application "Finder"
activate
select {¬
alias (thePath & "1.pdf"), ¬
alias (thePath & "2.pdf"), ¬
alias (thePath & "3.pdf") ¬
}
open selection
end tell
One can also programatically open multiple files using a list like so:
property thePath : "Macintosh HD:AppleScripts:"
property theFiles : {¬
"1.pdf", ¬
"2.pdf", ¬
"3.pdf"}
tell application "Finder"
activate
repeat with i from 1 to 3
open alias (thePath & item i of theFiles)
end repeat
end tell
However, using multiple open commands is slower than opening a selection of multiple files, especially with large lists.
What I would like is to programatically select multiple files, and then open the selection. Is this possible?
You can use lists of references in the Finder open command. When you open selection, you are using a list of Finder references with the open command. alias lists and lists of file references may also be used. Although string paths are not references, lists of these work also. The following script will error when the list of names are used:
tell application “Finder”
activate
set s to selection
set alias_list to {}
set path_list to {}
set name_list to {}
repeat with this_item in s
set end of alias_list to this_item as alias
set end of path_list to this_item as string
set end of name_list to name of this_item
end repeat
open alias_list
delay 1
close every window
open path_list
delay 1
close every window
open name_list – error
end tell
I used a couple of selected folders on the desktop here because their windows may easily be closed.
You can use names of disks also:
tell app “Finder”
open {“Macintosh HD”} – no error, these are disks
end tell
The best thing to do is use complete references (Finder, alias, and file references) because this is what the Finder dictionary says the clas of the direct parameter should be. You never know if a string path may not work in the next versions.
That’s because you’re giving the Finder lots of individual instructions to access the disk instead of sending it off with a single “shopping list”. But it’s not usually necessary to use the Finder’s selection in a script. You can use something like:
property thePath : "Macintosh HD:AppleScripts:"
property theFiles : {¬
"1.pdf", ¬
"2.pdf", ¬
"3.pdf"}
tell application "Finder"
activate
open (every file of folder thePath whose name is in theFiles)
end tell
Caveat: Unlike your original scripts, this won’t error if any of the files don’t exist.
Hi, Kel. I seem to remember noticing the same thing when I first started using Jaguar, but it’s working OK here now. I didn’t notice when it started going right. Perhaps it was with one of the updates. I’m up to 10.2.8 now, though the Finder’s still apparently 10.2.1. Strange… :?