Discussion:
How to Open Finder window from folder path in Cocoa
(too old to reply)
mhz
2005-12-03 15:33:11 UTC
Permalink
How to Open a Finder window showing the folder from the BSD directory path in Cocoa
l0ne (on mac)
2005-12-03 16:20:31 UTC
Permalink
Post by mhz
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
2005-12-04 15:07:01 UTC
Permalink
Post by l0ne (on mac)
Post by mhz
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.
- ∞
Exactly what I need!

Thank you.
Simon Slavin
2005-12-05 23:48:10 UTC
Permalink
On 03/12/2005, l0ne (on mac wrote in message
Post by l0ne (on mac)
Post by mhz
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.
--
http://www.hearsay.demon.co.uk
David Phillip Oster
2005-12-11 18:54:21 UTC
Permalink
Post by mhz
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
2005-12-11 22:15:03 UTC
Permalink
Post by David Phillip Oster
Post by mhz
How to Open a Finder window showing the folder from the BSD
directory path in Cocoa
@"tell application \"Finder\" to open posix file \"%@\"", path];
NSAppleScript* script =
[[NSAppleScript alloc] initWithSource: scriptString];
NSDictionary* errorDict = nil;
[script executeAndReturnError: &errorDict];
[script release];
The NSWorkspace answer mentioned earlier in this thread is faster and
better recommended.

-Eric
--
Eric Albert ***@cs.stanford.edu
http://outofcheese.org/
David Phillip Oster
2005-12-12 00:41:11 UTC
Permalink
...
Post by Eric Albert
Post by David Phillip Oster
NSAppleScript* script =
[[NSAppleScript alloc] initWithSource: scriptString];
NSDictionary* errorDict = nil;
[script executeAndReturnError: &errorDict];
...
Post by Eric Albert
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

Loading...