searching 100's of folders/files using "Finder" really slow

Hi

I have this script which uses “Finder” to troll through a mounted volume looking for files starting with or ending with certain names etc, the mounted volume that the finder has to search through has hundreds of files and folders in it and the finder takes such a long time to trudge through the finding process, Im sure using a shell command to find, list etc would be 10x faster than what I am using, problem is I don’t no unix.

Could I get some advice on how to implement unix, using do shell script, to replace the finder in this script, to make it faster please

on clicked theObject
------------------------------------------
if name of theObject is “SK_KNIVES” then
set _path to “KNIFE DRAWINGS:”
tell application “Finder”
set _list to (name of every file of entire contents of folder _path whose name starts with “SK”) as alias list
end tell
tell window “main”
delete every menu item of menu of popup button “_itemlist”
repeat with each_Item in _list
make new menu item at the end of menu items of menu of popup button “_itemlist” with properties {name:each_Item, title:each_Item, enabled:true}
end repeat
end tell
------------------------------------------
else if name of theObject is “VK_KNIVES” then
set _path to “KNIFE DRAWINGS:”
tell application “Finder”
set _list to (name of every file of entire contents of folder _path whose name starts with “VK”) as alias list
end tell
tell window “main”
delete every menu item of menu of popup button “_itemlist”
repeat with each_Item in _list
make new menu item at the end of menu items of menu of popup button “_itemlist” with properties {name:each_Item, title:each_Item, enabled:true}
end repeat
end tell
------------------------------------------
else if name of theObject is “_Illustrator” then
set _path to “KNIFE DRAWINGS:”
tell application “Finder”
set _list to (name of every file of entire contents of folder _path whose name ends with “.ai”) as alias list
end tell
tell window “main”
delete every menu item of menu of popup button “_itemlist”
repeat with each_Item in _list
make new menu item at the end of menu items of menu of popup button “_itemlist” with properties {name:each_Item, title:each_Item, enabled:true}
end repeat
end tell
------------------------------------------
else if name of theObject is “_select” then
tell application “Finder”
set theFile to (choose folder without invisibles)
set _list to (name of every file of entire contents of folder theFile)
end tell
tell window “main”
delete every menu item of menu of popup button “_itemlist”
repeat with each_Item in _list
make new menu item at the end of menu items of menu of popup button “_itemlist” with properties {name:each_Item, title:each_Item, enabled:true}
end repeat
end tell
end if
------------------------------------------
if name of theObject is “get” then
set _path to “KNIFE DRAWINGS:”
set _selecteditem to title of current menu item of popup button “_itemlist” of window “main” as text
tell application “Finder” to set FileToOpen to ((get 1st file of entire contents of folder _path whose name is _selecteditem) as alias)
tell application “Adobe Illustrator” to open FileToOpen
end if
------------------------------------------
if name of theObject is “cancel” then
quit me
end if
------------------------------------------
end clicked

Cheers
Budgie

Ive managed to get this far (put together from snippets of scripts written by StefanK), which is working pretty well after I adapted them to suit me, and is way faster than what I had.

on clicked theObject
------------------------------------------
if name of theObject is “SK_KNIVES” then
set _path to quoted form of POSIX path of “KNIFE DRAWINGS:”
set _title to “SK”
set _list to paragraphs of (do shell script “find " & _path & " -type f -name ‘" & _title & "’ ! -name ‘.*’”)
tell window “main”
delete every menu item of menu of popup button “_itemlist”
repeat with each_Item in _list
make new menu item at the end of menu items of menu of popup button “_itemlist” with properties {name:each_Item, title:each_Item, enabled:true}
end repeat
end tell

Just a couple of questions:

1)The script above returns this in my pop up button
/Volumes/KNIFE DRAWINGS//000/Reel Feed/SK100350/SK000350 .ai

how can I get it to return just the file name SK000350 .ai not the complete path to the file?

2)In the script below a file is made on the desktop, which then has the copied file chosen from the pop up button placed in it, how would I have just the file placed on the desktop, and not have the folder created?

if name of theObject is “get” then
set inputFolder to quoted form of POSIX path of “KNIFE DRAWINGS:”
set keyword to title of current menu item of popup button “_itemlist” of window “main” as text
set newname to “COPY”
– search with find
set foundFiles to paragraphs of (do shell script “find " & inputFolder & " -type f -name ‘" & keyword & "’ ! -name '.'")
– search with mdls
–set foundFiles to paragraphs of (do shell script "mdfind -onlyin " & inputFolder & " 'kMDItemFSName = "
” & keyword & “*"'”)
set dest to do shell script “mkdir -v ~/Desktop/” & newname – makes new folder at desktop
repeat with i in foundFiles
try
do shell script "cp " & quoted form of i & space & quoted form of dest
end try
end repeat
end if

cheers
Budgie

Hi Budgie,

  1. One way to do this would be:
set the_file to "/Volumes/KNIFE DRAWINGS/000/Reel Feed/SK100350/SK000350.ai"
set tempdelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set the_file_name to the_file as string
set the_file_name to text items of the_file_name
set the_file_name to item -1 of the_file_name
set AppleScript's text item delimiters to tempdelim

the_file_name
—>“SK000350.ai”

  1. In this part of your script:

You are actually creating the foldr with mkdir… So if you don’t want to do that, you should get rid of that command.

-patrick

If you use the call method command/function you should be able to access the NSFileManager routines of Cocoa.

You would obviously need to understand how to use Call Method. There are lots of examples on this list.

See description of what is available at:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

These routines should be quicker than the Finder

All the best

Terry

wow, im gob smacked, :smiley:

Jacques, thankyou for your time and knowledge, your script is dam fast and works like a dream, ill be going over your script in detail to learn from it, and looking at it, ive got a lot to learn.

Thanks very much for your input -patrick and tellboy, got some new stuff to learn also from your suggestions.

awsome

cheers
Budgie