UNIX Find within Applescript

– this works searching a file on my laptop
set Search_Folder to “Macintosh HD:Users:shawn:Desktop:Test”
set Search_Folder2 to POSIX path of Search_Folder --Macintosh HD/Users/shawn/Desktop/Test
set search_word to “zzasdasd”
set x to (do shell script “find " & Search_Folder2 & " -name zzasdasd*”)
– Test folder has 5 subfolders, each folder has 40 files, shell script find, finds the file in blink of an eye

– this does not work, accessing a server at work
set search_word to text returned of result & "" as string – campy
set Search_Folder to “10.10.x.x:AudioNAS:Ah2”
set Search_Folder2 to POSIX path of Search_Folder – /10.10.x.x/AudioNAS/Ah2
set x to (do shell script "find " & Search_Folder2 & " -name " & search_word)
– here is the error I get:
– error “Finder got an error: find: /10.10.x.x/AudioNAS/Ah2/: No such file or directory” number 1

any idea why it adds a “:”
thanks for any help.

A mounted shared volume is located in /Volumes, in this case I recommend to specify the POSIX path directly

set Search_Folder to "/Volumes/AudioNAS/Ah2"

The HFS counterpart is simply

set Search_Folder to "AudioNAS:Ah2"

And add always quoted form of to POSIX paths in do shell script lines to escape special characters

set x to (do shell script "find " & quoted form of Search_Folder2 & " -name " & search_word)

not working, I get the spinning gear and “running” at the bottom of the editor window. after 30 seconds I get “” as the result. Dang.

tell application “Finder”

set Search_Folder to "/Volumes/AudioNAS/Ah2"
set search_word to "*campy*"
set x to (do shell script "find " & quoted form of Search_Folder & " -name " & search_word)

end tell

when the search word is “Campy” not “campy”, it finds all files with Campy but it takes 1 minute. Wow. Slow as molasses.

can you search with caps not being a factor.

Is there a faster way. shell scrip find on my laptop is INSTANT.

this is not working. It gets hung up on getting the quoted form:

tell application “Finder”
set search_word to “Campy

repeat with a_folder in folder "AudioNAS:Ah2:Comedy:"
	
	repeat with a_sub_folder in folder in a_folder
		set x to (do shell script "find " & quoted form of a_sub_folder & " -name " & search_word) as string
	end repeat
	
end repeat

end tell

You have to convert Finder specifier to POSIX path

 set x to do shell script "find " & quoted form of POSIX path of (a_sub_folder as text) & " -name " & search_word

The coercion as string is redundant as the result of do shell script is always string.

And actually the loop is redundant, too, because find performs a deep search in all subfolders.

Hi.

You can’t get the quoted form of a Finder reference, only of text.

I’m not clear if your server volume is “10.10.xx” or "AudioNAS. If it’s the former, you probably need:

set Search_Folder to "/Volumes/10.10.xx/AudioNAS/Ah2"
set search_word to "*campy*"
set x to (do shell script "find " & quoted form of Search_Folder & " -name " & quoted form of search_word)
  1. You don’t need to invoke the Finder for ‘do shell script’.
  2. ‘find’ is recursive and will search every subfolder of the search folder, so you don’t need a repeat.
  3. Since you’ve been a MacScripter member for over thirteen years, do you think you could learn to use our [applescript] and [applescript] tags when posting code? :wink:

yes I will use the tags.

Here is the error I got when I ran your suggested code. Below is not really code right, so here is just the text.

“find: /Volumes/10.10.x.x/AudioNAS/Ah2: No such file or directory” number 1

Yeah that’s fine. The tags are just for AppleScript code which people may want to look at in their script editors. Clicking the “Open this Scriplet in your Editor:” link above the posted code opens the code in their default editors automatically, although there are a couple of security checks to OK during the process nowadays.

So we’re still trying to find the correct POSIX path to the folder on your server.

Since the folder’s on a disk other than your startup disk, the path must begin with “/Volumes”, as above. Then there should be another slash, followed by the name of the server mount point as it appears on your desktop. Then more slashes and names reflecting the path down through the folder hierarchy from the mount point to the folder you want to search. The path in my script supposes a mounted volume called “10.10.xx” on your desktop, which contains a folder called “AudioNAS” and, in that, a folder called “Ah2”, which the script searches for items whose names contain “campy” in lower-case letters. The names in the path too must agree in case with those on the server. The script will only work while the server volume’s mounted.

The server 10.10.x.x is visible in the sidebar under shared.
The Main folder AudioNAS is visible in a Finder window
so far so good
The error shows a “:” after the path. A “:” should not be in the path
should be /volumes/shares/folder/folder/

can’t figure out how to get rid of the “:”
campy does need to be Campy to match the file name.

thanks, I’ll run more tests tomorrow at work.

Don’t worry about the colons. They’re just there to separate the parts of the error message.

If you have the folder “AudioNAS” open in the front Finder window, you can get the path to the folder “Ah2” in it with this:

tell application "Finder" to set searchFolder to target of front Finder window as alias
set Search_Folder to (POSIX path of searchFolder) & "Ah2"

You can either include this at the top of your script or run it and paste the result into your own ‘set Search_Folder …’ line.

this works but takes a while to pop up the results. Like 1 minute. I was hoping for 5 seconds.

set Search_Folder to "/Volumes/AudioNAS/AH2"
set search_word to "* Campy *"
set x to (do shell script "find " & quoted form of Search_Folder & " -name " & quoted form of search_word)

I don’t know. :confused: I’m getting pretty instantaneous results quizzing a large folder on another Mac in the same room at home over a wi-fi connection. But there could be all sorts of things to slow down communication with an office server, such as distance, how many other computers it’s having to serve, what else it’s doing in the background, the fact that “find”'s searching another machine’s drive, etc. There may not be anything that can be done to speed it up, scriptwise. :confused:

I also setup a test scenario with lots of folders and lots of files and it took seconds. Wish is was faster. Thanks for all your help.