This must be easy, haven’t found the answer after hours of digging. Essentially want to locate the path to a file no matter where it is located on any computer. The script so far goes like this:
set openFile to ((path to desktop as string) & “GAC Database:Open All”)
tell application “Finder”
if not (exists openFile) then
set openFile to choose file with prompt “Please locate the ‘Open All’ file:”
end if
end tell
tell application “FileMaker Pro”
activate
ignoring application responses
open openFile
end ignoring
end tell
How to always locate the file ‘Open All’ is the question.
I think you’ve chosen the best way, because it is the quickest one…
If I had to find the file myself without user input, I’d take a look to X-Commands’ command “file search”, which seems (for me) pretty fast.
First, NEVER use “path to desktop as string”. It isn’t safe.
Under Mac OS X, ‘path to desktop’ will return the USER’S desktop folder (/Users/username/desktop/" which will be different for every user who logs into the system.
There is also a global desktop (/Desktop) which contains items common to all users, but that’s disk (volume) specific, and still may not cover what you need.
To manually search the disk for a specific file could take some time.
I think the best you can hope for is to search a few known locations, such as:
If the script is in the same location as the files you’re looking for:
(path to me) & “GAC Database:Open All”
Search known locations:
every file of startup disk whose name is “Open All” – top level of startup disk
tell folder “GAC Database”
set theFile to (every file whose name is “Open All”) – file is in a top-level folder called “GAC database”
end tell
Searchiing specific, known locations is very quick. Include a couple of likely locations, then fall back to asking the user for assistance if the file isnt’ found,
Under Mac OS X, ‘path to desktop’ will return the USER’S desktop folder (/Users/username/desktop/" which will be different for every user who logs into the system.
This is exactly what I’m looking for. If the folder with the files is placed on any users desktop, it will find it. However, when copying the files to other users desktops, somehow it stops working. The only workaround seems to be to save a copy of the script directly on each users machine. Bad news!