Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 8, 2008, 07:47 AM   #1
phjo
macrumors regular
 
Join Date: Jan 2008
Reveal to finder : multiple selection ?

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
phjo is offline   0 Reply With Quote
Old Mar 8, 2008, 10:16 AM   #2
MacDonaldsd
macrumors 65816
 
MacDonaldsd's Avatar
 
Join Date: Sep 2005
Location: 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.
MacDonaldsd is offline   0 Reply With Quote
Old Mar 8, 2008, 12:15 PM   #3
phjo
Thread Starter
macrumors regular
 
Join Date: Jan 2008
I thought I was getting nearer with the Scripting Bridge framework, as reading from http://download.info.apple.com/Apple...inderGuide.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
phjo is offline   0 Reply With Quote
Old Mar 8, 2008, 12:28 PM   #4
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
This page might be of some help: http://yost.com/computers/MacStuff/reveal/index.html
kainjow is offline   0 Reply With Quote
Old Mar 8, 2008, 02:48 PM   #5
phjo
Thread Starter
macrumors regular
 
Join Date: Jan 2008
Quote:
Originally Posted by kainjow View Post
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
phjo is offline   0 Reply With Quote
Old Mar 8, 2008, 02:59 PM   #6
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
It might not be possible through Obj-C, but that doesn't mean you can't do it via NSAppleScript.
kainjow is offline   0 Reply With Quote
Old Mar 9, 2008, 05:30 AM   #7
phjo
Thread Starter
macrumors regular
 
Join Date: Jan 2008
Quote:
Originally Posted by kainjow View Post
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
phjo is offline   0 Reply With Quote
Old Mar 9, 2008, 05:50 AM   #8
hhas
macrumors regular
 
Join Date: Oct 2007
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;
}
__________________
Learn AppleScript, 3rd edition, Sanderson & Rosenthal:
http://www.apress.com/9781430223610
hhas is offline   0 Reply With Quote
Old Mar 9, 2008, 09:20 AM   #9
phjo
Thread Starter
macrumors regular
 
Join Date: Jan 2008
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
phjo is offline   0 Reply With Quote
Old Mar 9, 2008, 11:16 AM   #10
hhas
macrumors regular
 
Join Date: Oct 2007
Quote:
Originally Posted by phjo View Post
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/documenta...rameworks.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).
__________________
Learn AppleScript, 3rd edition, Sanderson & Rosenthal:
http://www.apress.com/9781430223610
hhas is offline   0 Reply With Quote
Old Mar 9, 2008, 11:59 AM   #11
phjo
Thread Starter
macrumors regular
 
Join Date: Jan 2008
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...
phjo is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Change Finder Sidebar BG and Selection Color 82asmdf203 OS X Mavericks (10.9) 5 Oct 20, 2014 05:59 PM
help with multiple finder sidebar Favorites with same name unfrostedpoptar OS X Mavericks (10.9) 4 May 14, 2014 08:29 PM
How do you reveal the location of an open file in Finder? thegarlicknight Mac Basics and Help 6 Nov 14, 2013 06:32 PM
OS X 10.9 to Bring Enhancements to Finder, Safari, Multiple Monitor Support, and Multitasking MacRumors MacRumors.com News Discussion 443 Jun 9, 2013 07:45 AM
Running multiple actions on multiple items selection 1theo0 Mac Programming 1 Dec 21, 2012 07:44 AM

Forum Jump

All times are GMT -5. The time now is 06:31 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC