Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / December 2005



Tip: Looking for answers? Try searching our database.

How to Open Finder window from folder path in Cocoa

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mhz - 03 Dec 2005 15:33 GMT
How to Open a Finder window showing the folder from the BSD directory path in Cocoa
l0ne (on mac) - 03 Dec 2005 16:20 GMT
> How to Open a Finder window showing the folder from the BSD directory path
> in Cocoa

What you need is the -openFile:, -openURL: or
-selectFile:inFileViewerRootedAtPath: methods of the NSWorkspace class.

- ∞
mhz - 04 Dec 2005 15:07 GMT
> > How to Open a Finder window showing the folder from the BSD directory path
> > in Cocoa
[quoted text clipped - 3 lines]
>
>  - ∞

Exactly what I need!

Thank you.
Simon Slavin - 05 Dec 2005 23:48 GMT
On 03/12/2005, l0ne (on mac wrote in message
<1h70844.yi1t6twccsaoN%millenomi@gmail.com>:


> > How to Open a Finder window showing the folder from the BSD directory
> > path in Cocoa
>
> What you need is the -openFile:, -openURL: or
> -selectFile:inFileViewerRootedAtPath: methods of the NSWorkspace class.

Just to clarify that, think of the folder as if it was a file.  The
application which opens folders is the Finder.  So when you tell the
operating system to open a folder, it tells the Finder to open a
window showing its contents.

Simon.
Signature

http://www.hearsay.demon.co.uk

David Phillip Oster - 11 Dec 2005 18:54 GMT
> How to Open a Finder window showing the folder from the BSD directory path in
> Cocoa

Here is some actual, tested, working, source code:

NSString* path = @"/Developer/Applications";
NSString* scriptString = [NSString stringWithFormat:
@"tell application \"Finder\" to open posix file \"%@\"", path];
NSAppleScript* script =
 [[NSAppleScript alloc] initWithSource: scriptString];
NSDictionary* errorDict = nil;
[script executeAndReturnError: &errorDict];
[script release];

Obviously, in a real program:

You'd want to look at the autoreleased errorDict from
executeAndReturnError.

You'd need to process 'path' to escape any backslashes and double quote
characters in it.

David Phillip Oster
Eric Albert - 11 Dec 2005 22:15 GMT
> > How to Open a Finder window showing the folder from the BSD
> > directory path in Cocoa
[quoted text clipped - 9 lines]
> [script executeAndReturnError: &errorDict];
> [script release];

The NSWorkspace answer mentioned earlier in this thread is faster and
better recommended.

-Eric

Signature

Eric Albert         ejalbert@cs.stanford.edu
http://outofcheese.org/

David Phillip Oster - 12 Dec 2005 00:41 GMT
...
> > NSAppleScript* script =
> >   [[NSAppleScript alloc] initWithSource: scriptString];
> > NSDictionary* errorDict = nil;
> > [script executeAndReturnError: &errorDict];
...

> The NSWorkspace answer mentioned earlier in this thread is faster and
> better recommended.
>
> -Eric

You are quite right. Thanks for the correction.

David Phillip Oster
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.