Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

phjo

macrumors regular
Original poster
Jan 8, 2008
149
1
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

macrumors 65816
Sep 8, 2005
1,005
0
London , UK
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

macrumors regular
Original poster
Jan 8, 2008
149
1
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

Moderator emeritus
Jun 15, 2000
7,958
7
It might not be possible through Obj-C, but that doesn't mean you can't do it via NSAppleScript.
 

phjo

macrumors regular
Original poster
Jan 8, 2008
149
1
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

macrumors regular
Oct 15, 2007
126
0
Using objc-appscript:

Code:
#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

macrumors regular
Original poster
Jan 8, 2008
149
1
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

macrumors regular
Oct 15, 2007
126
0
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/document...al/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

macrumors regular
Original poster
Jan 8, 2008
149
1
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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.