Scripting the Jaguar Finder's Find ability?

Hello all!

I think i actually like the new BBS system, although an option to see both pre-X and X simultaneously would be nice. I like the fact that you see whole threads without following a dozen links, though. Also, it’s faster.

Anyway, to my actual subject: Has anyone discovered whether the Finder team has actually talked to the poor AppleScript guys at Apple and managed to get some scriptability for the new whiz-bang feature: finding files using the Finder?

It doesn’t look like it. In fact, if you ask the Finder for window 1 when the Find dialog is up, it tells you the first window behind that is the frontmost window. However, a Search Results window is visible to AppleScript and has list view options, etc. Very odd. I wish that when developers (including Apple!) added new features to Mac apps, they’d update the AppleScript. Mozilla has similar problems: the Do Javascript command does not seem to work, and window tabs in Tabbed Browsing are inaccessible. Annoying.

Anyone have any insight?

I’m not sure if I follow your question correctly, but if you want your script to bring the frontmost window to the foreground, you might try this…

tell application "Finder"
	activate
	get window frontmost
end tell

Thanks for the comments on the New BBS

Nope. What I meant was: we no longer use Sherlock to search for files, but the Finder itself. I was hoping Apple’s Finder team had bothered to make that Find command available to scripters. I tried to access the Find window using AppleScript, even though it is not the dictionary, but it seems impossible. If a Find window is the frontmost, and you ask for
name of window frontmost
you get the window behind the Find window. However, a Search Results window can be read from AppleScript. Seems like another “halfway” implementation to me.

I agree with your comments on half-way implementations, but I think you can overcome this. You can script activate the finder, use X-commands:

tell application “Finder” to activate
tell application “X-Commands”
type key “F” with command
delay 2
type string “bobo” —> or your search string
delay 1
type key “return”
end tell

This compromises in a way that you need to have the right fields activated etc.
From here you can script the results window

Just a friendly reminder to download the new version of “Extra Suites”
(x-commands final release name)
after december 30 (the expiration date)

Just a little plug for David Lloyd :smiley:

A good idea if I really needed to use this, but scripting via macros isn’t really scripting, it’s macros. I was hoping for a “run command - get results” kind of interface. For example, to change the name of a file in the Finder, you don’t need to open the folder it’s in, click on the name and type. In fact, you don’t need any visual feedback at all. X-Commands et al (Youpi Keys is what I’ve used) are great, but often you don’t want random things changing on the screen.

I suppose I could wrap the command-line find into an AppleScript handler. Anyone already done this? Oh, and this is an academic question, really - I don’t currently need to do this.

I’m confused as to why you want to.

For a start, the Finder’s Find command is a graphical front end to a find utility. It doesn’t offer anything you can’t already do in a script, and usually the reason you want to write a script is to overcome the burden and overhead of using a gui.

In its simplest terms:

tell application “Finder”
get every file of disk “Macintosh HD” whose name contains “System”
end tell

in effect executes a find on the top level of your disk.

You can differentiate between files and folder by adjusting the syntax, but you do need to play a few games to deal with recursion.

Alternatively, there’s the venerable:

do shell script “find / -name “System””

The pieces of code that you supply do not match Finder’s gui Find power,let alone be an alternative or providing the functionality behind the Finder’s find gui. The reason behind scripting “Find” is, as I guess, not to overcome burden and overhead but the ability to further use the search results in a script.

I tried:

every item in every folder of startup disk whose name contains "system"

but that doesn’t work either.

I guess we need to wait for an alternative to a nice and fast “find” OSAX like Akua in classic.

Eelco: I think what Camelot meant was that there was some functionality in the Finder (although I admit I don’t trust it much at all, due to past history). Also, the command-line utility ‘find’ is very useful, but does not easily access all the options the Finder has. For example, I don’t see anything in find’s man pages that explains how to search for a given file type or the date created, only the date modified.

In short, having an easy-to-use AppleScript interface to the Finder’s ability to find files would be useful, and certainly should be added.

Just as a side note:

There’s an osax that has made my life much easier for finding files. It’s FindFile.

http://www.microcosmsoftware.com/findfileosax.html

Search anything from file names, types, creators, file kind, file sizes, comments, versions and the list goes on and on. It’s a remarkable tool for finding just the right file.

Alas, it’s a classic osax. The author has hinted on an OS X version. Maybe a little encouragement will make it a reality? :wink:

Anyway, a plug to David Blache.