Re: How to launch Finder with given directory from Carbon app
Re: How to launch Finder with given directory from Carbon app
- Subject: Re: How to launch Finder with given directory from Carbon app
- From: Ken Thomases <email@hidden>
- Date: Wed, 11 Feb 2009 09:25:49 -0600
On Feb 11, 2009, at 8:19 AM, Philippe Casgrain wrote:
On 2009-02-11, at 03:36 , Dieter Oberkofler wrote:
How would I launch the Finder with a given directory from a Carbon
app?
(In the Windows API this would be done by using ShellExecute(...,
"explore", "/mydirectory", ...). What is the counterpart in the
Carbon
API?)
Send an 'open' AppleEvent to the Finder with the folder to open as a
parameter. You can also use AppleScript, which amounts to the same
thing, but you can store a string in your resources instead of
compiled code:
'tell application "Finder" to open "/mydirectory"'
Here is a function, SimpleRunAppleScript, which takes a string
representing an AppleScript and runs it.
(Note: "TMCStringUTF8" is our own UTF-8 string class. Substituting
your own, or CFString, is an exercise for the reader).
Wow, is that the wrong approach!
I already answered Dieter off-list, since this is off-topic for xcode-
users, but this needs to be corrected.
The correct way to open things (documents, applications, folders,
URLs) is with Launch Services. For this simple task, you could use
LSOpenCFURLRef. You can get a CFURL for a file path string using
CFURLCreateWithFileSystemPath or
CFURLCreateFromFileSystemRepresentation.
Regards,
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden