Reveal to finder : multiple selection ?

Discussion in 'Mac Programming' started by phjo, Mar 8, 2008.

  1. macrumors regular

    Joined:
    Jan 8, 2008
    #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
     
  2. macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #2
    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.
     
  3. thread starter macrumors regular

    Joined:
    Jan 8, 2008
    #3
    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
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
  5. thread starter macrumors regular

    Joined:
    Jan 8, 2008
    #5
    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
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    It might not be possible through Obj-C, but that doesn't mean you can't do it via NSAppleScript.
     
  7. thread starter macrumors regular

    Joined:
    Jan 8, 2008
    #7
    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
     
  8. macrumors regular

    Joined:
    Oct 15, 2007
    #8
    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;
    }
    
     
  9. thread starter macrumors regular

    Joined:
    Jan 8, 2008
    #9
    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
     
  10. macrumors regular

    Joined:
    Oct 15, 2007
    #10
    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).
     
  11. thread starter macrumors regular

    Joined:
    Jan 8, 2008
    #11
    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...
     

Share This Page