PDA

View Full Version : Reveal to finder : multiple selection ?




phjo
Mar 8, 2008, 07:47 AM
Revealing in finder one file is easy with selectFile:inFileViewerRootedAtPath: method of NSWorkspace.

But how would one obtain multiple file selection in finder ?

(supposing that is possible, of course)

phjo



MacDonaldsd
Mar 8, 2008, 10:16 AM
Hi,

As far as I can see it always opens it in the same finder window when I loop through a few files, and therefore displays the last file in the finder, which is strange.

phjo
Mar 8, 2008, 12:15 PM
I thought I was getting nearer with the Scripting Bridge framework, as reading from http://download.info.apple.com/Apple_Support_Area/Manuals/servers/AppleScriptFinderGuide.PDF
it seems like it is possible with Applescript to reveal in Finder a selection of several files, provided they are in the same container (which sounds reasonable enough...)

But I was only able to select individual files by using the construct :

FinderItem *theItem = [[finder items] objectAtLocation: *NSURL];

and reveal it with :

[theItem reveal];

but I would need a way to reveal a list of files, by calling only once a reveal method of some sort...

I am a bit lost in the documentation, and the fact that I know about nothing about applescript, and not that much about cocoa doesn't help...

For MacDonaldsd, yes, I have the same experience. There is nothing surprising to see only one file selected, but I would have expected to see as many finder windows opening when using :
selectFile:inFileViewerRootedAtPath: method...

phjo

kainjow
Mar 8, 2008, 12:28 PM
This page might be of some help: http://yost.com/computers/MacStuff/reveal/index.html

phjo
Mar 8, 2008, 02:48 PM
This page might be of some help: http://yost.com/computers/MacStuff/reveal/index.html

Well, it does confirm what I read, that multiple selection is possible through applescript (again, provided all files are in one same container), but it doesn't tell me how to do it using objective-c.

phjo

kainjow
Mar 8, 2008, 02:59 PM
It might not be possible through Obj-C, but that doesn't mean you can't do it via NSAppleScript.

phjo
Mar 9, 2008, 05:30 AM
It might not be possible through Obj-C, but that doesn't mean you can't do it via NSAppleScript.

You're right... something else to learn and try...

I'd prefer a more integrated way of doing things though, but I'll give it a try later on, thanks.

phjo

hhas
Mar 9, 2008, 05:50 AM
Using objc-appscript (http://appscript.sourceforge.net/objc-appscript.html):


#import "FNGlue/FNGlue.h"

// To create Finder glue: osaglue -o FNGlue -p FN Finder

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

FNApplication *finder = [[FNApplication alloc] initWithBundleID: @"com.apple.finder"];

NSArray *files = [NSArray arrayWithObjects:
[NSURL fileURLWithPath: @"/Users/has/Documents"],
[NSURL fileURLWithPath: @"/Users/has/Movies"],
[NSURL fileURLWithPath: @"/Users/has/Pictures"],
nil];

NSError *err;
[[finder activate] send];
[[finder select: files] sendWithError: &err];

if (err) NSLog(@"%@", err);

[finder release];
[pool drain];
return 0;
}

phjo
Mar 9, 2008, 09:20 AM
Interesting ! By browsing the web looking for solutions for this problem, I found out about objc-appscript, but I didn't pay much attention to it...

Now the code that hhas pasted looks very nice so it motivated me to try it, and it works just fine indeed... Furthermore, it allows to select files in several containers, which makes then Finder open as many windows as there are containers.

A question though, although I am ages from distributing any software, I wonder about the distribution of it, when in binary form. Of course, whoever needing to build one application from the source will need to install (download with subversion from sourceforge, building with xcode...) the AppScript framework but is it the case as well for binary distribution ?

I would guess some kind of static linking should be possible, but I am not sure it is the default, or how you would trigger such a building... (yeah, I am a newbie in osx programming, and will remain one for many months to come I guess...)

phjo

hhas
Mar 9, 2008, 11:16 AM
A question though, although I am ages from distributing any software, I wonder about the distribution of it, when in binary form.

Just include Appscript.framework in your application bundle as a private framework. Tutorials covering this stuff in more detail are currently being written; in the meantime, see:

http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

Appscript is MIT licensed, so can be freely included and redistributed within your own applications (with the minor requirement that you also include its original license).

phjo
Mar 9, 2008, 11:59 AM
Yes, embedding the framework (or as a private framework) is the way to go... That's for a very uncertain future though...

Many thanks for your help, hhas, and for your work.

phjo

P.S. : one can only regret to see Apple trying to reinvent the wheel and propose a new and different framework instead of maybe hiring you and make your framework part of Apple frameworks...