I’ve looked and so far haven’t found an answer to this.
I am trying to write an applescript in OS X 10.3.4 that will
open the Find function of Finder, and select a specific folder to search in.
set the search criteria to “contents”
remove any additional search criteria left from the last search
If we want to get real fancy, the specific folder is on a server, so if the user is not currently connected we could do some error handling and open the dialog to connect to the server (this would be using the Finder’s Go → Connect to server function)
I am experienced in writing C++, and am having trouble switching to this “natural” language.
Likely, if someone could tell me how to find out what the different fields and objects in a particular window are, then I could write it myself.
But I will take all the help I can get.
Thanks in advance for the help. By the way, this is the best A.S. Forum i’ve found, so keep it up!
OK, thank you so much, jj, for the code you sent me. It does it’s job well. I have two more questions.
How do I enter the path to a server location? The server is mounted, but I’m just not sure how to specify the path.
How can I parse out the reults into a window or text file so that it shows the path to the file, and the filename, but not the other information. Making these clickable links (alias’) to the files would also be VERY handy.
Please excuse my naiveness, I am a very recent Mac Convert too.
I’m trying to put in an error handler that verifies the path exists first.
something like this (this code doesn’t work, btw)
if not (exists path '/users/blah/desktop/dsld') then
activate application "Finder"
tell application "System Events"
tell process "Finder"
keystroke "k" using command down
end tell
end tell
end if
Usually, “/Volumes/DISKNAME/dir/subdir” (that is, disks are mounted under the “/Volumes” folder).
This may get you started:
However, I’ve seen that the “find” method doesn’t work properly if you search for special characters… I’m writing a suite of utilities, so I added this one:
Cool. I’ve got everything working the way I want it, except for one little thing.
Each time results are returned to the finder, the first result is always to an index file. I do not want that to show up each time, and I’m not sure how to get rid of it.
Here’s the slightly modified code I’m working with now.
set x to quoted form of POSIX path of alias "path:name"
display dialog "Search Criteria" default answer "" buttons {"OK"} default button 1
set y to text returned of the result
try
set theResult to paragraphs of (do shell script "find " & x & " -type f -exec grep -i " & y & " {} /dev/null \;")
set aliasizedStuff to {}
repeat with var in theResult
set aliasizedStuff's end to text 14 thru ((offset of " matches" in var) - 1) of var as POSIX file as text
end repeat
end try
if aliasizedStuff is {} then
display dialog "No matches"
else
choose from list aliasizedStuff
if result is not false then tell application "Finder" to open {result as text as alias}
end if