Hello,
New to the boards and just starting to look at AppleScript.
I’m interested in being able to open a file of which I know the path but that I only know, say, the left 5 characters of the file name.
I’ve tried using the ~ and * characters after the file name as wildcards but I receive and error…
Finder got an error: Can’t get document file “volume:sub_folder1:sub_folder2:file*”.
Unknown Error: -1728.
I can script the path ok so that I can present the window with the proper directory showing but I can’t make the last step of being able to open the file.
Any help would be appreciated.
Thanks!
Hi Brian,
the AppleScript equivalent is
tell application "Finder"
open (get files whose name starts with "file")
-- or:
-- open (get 1st file whose name starts with "file")
end tell
Note: if no path is specified, the “root” directory of the Finder (but not of System Events!) is
the desktop folder of the current user
Ok, that furthers me along, although my scripting abilities are painfully lacking.
I was assuming that once the window was presented that AppleScript would remember/know/default to that as the current path for the file I want to open. Oh how wrong I am.
So, I can get a window open to a specific directory and thanks to Stefan I can open a file on my Desktop. How to I merge the two together so that the “file” part of
open (get files whose name starts with "file")
knows what path I want?
Thanks!
Hi Brian,
you can open files of the active (open) Finder window with
tell application "Finder" to open (get files of (get insertion location) whose name starts with "file")
Alright, seem to be making progress…
I get the error:
Can’t get every file of “volume:sub_folder1:sub_folder2:”.
Here is what my script looks like:
tell application "Finder"
open (get files of (get "volume:sub_folder1:sub_folder2:") whose name starts with "value")
end tell
The path and the file name are variable. The path shows up in the error, though the file names does not. I hard coded the variables to the known path and file name to eliminate the possibility of them being incorrect.
Stefan, thanks for the quick responses. I really appreciate your time, patience and help.
Thanks!
if you specify the folder by a string path, use the syntax
tell application "Finder"
open (get files of folder "volume:sub_folder1:sub_folder2:" whose name starts with "value")
end tell
Stefan,
Thanks again for the help!
Everything seems to be working now as intended.