Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > File Finding with Applescript?

File Finding with Applescript?
Thread Tools
Professional Poster
Join Date: Jan 2001
Location: Between Sydney and Melbourne
Status: Offline
Reply With Quote
Mar 14, 2004, 06:00 AM
 
Does anyone know how to access the finders "find..." command from within Applescript.
GUI scripting is not really an option.

Thanks.
     
JNI
Forum Regular
Join Date: Oct 2002
Location: Left Coast
Status: Offline
Reply With Quote
Mar 14, 2004, 11:06 AM
 
Originally posted by moonmonkey:
Does anyone know how to access the finders "find..." command from within Applescript.
GUI scripting is not really an option.

Thanks.
I don't think the Find feature of the Finder is scriptable. I don't see it anywhere in the Finder dictionary.

I think your best bet would be to call through to the BSD subsystem 'find' command using the 'do shell script' feature of AppleScript. See 'man find' from a terminal. It's a bit difficult to harness its power, but if you post a an example of what you want to do, someone could probably help in hooking that up.

You could also hand-roll a way to search the filesystem using pure AppleScript, but it will probably be like thousands of times slower than using BSD find, and it would be probably dozens if not hundreds of lines of AppleScript code. Wrapping BSD find in AS will still probably be a dozen or so lines in AS, depending on what kind of options you want to expose to the user.
(Last edited by JNI; Mar 14, 2004 at 11:12 AM. )
     
Professional Poster
Join Date: Jan 2001
Location: Between Sydney and Melbourne
Status: Offline
Reply With Quote
Mar 15, 2004, 03:50 AM
 
Originally posted by JNI:
but if you post a an example of what you want to do, someone could probably help in hooking that up.
I want a script which displays a window with files who's modification date is today.
i'm stumped.
     
JNI
Forum Regular
Join Date: Oct 2002
Location: Left Coast
Status: Offline
Reply With Quote
Apr 1, 2004, 10:12 AM
 
Originally posted by moonmonkey:
I want a script which displays a window with files who's modification date is today.
i'm stumped.
I looked a bit into this and found that because the UI capabilities of a simple AppleScript are so limited, it becomes a problem if you want to show a list of more than a few entries. It would probably be better to use AppleScript Studio so that you could have a scrolling text box or a table or something to display the results. But I don't see why you would want to do that, since if you just run the find command from the terminal, that's already what it will do. Unless you then wanted to interact with the list or something, then you might want to add more UI like a sortable list, or buttons to invoke actions on the elements or something like that.

The basics of what you would do if you want to pursue an AS solution would be to construct the arguments to the find command and call 'do shell script' with the constructed command. Then you would need to take the returned esults and decide how you want to display them. As I said, in a simple AppleScript, your UI options are limited. You could put it into a list using the 'choose from list' command, but that's about it, and not a very pleasing solution.

If you see 'man find' there is an example of how to find recently modified files.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2