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: Philip Aker <email@hidden>
- Date: Wed, 11 Feb 2009 16:00:25 -0800
On 2009-02-11, at 07:25:49, Ken Thomases wrote:
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.
The above assessment of Philippe's approach is not acceptable.
Using OSA calls to attain a result is just as viable as using
LaunchServices because in every case it will call through to lower
level systems services on your behalf. In fact, one can make the
argument that with even a basic knowledge of AppleScript, one could
use its functionality at the OSA level to attain a substantial
percentage of system services an application would normally make with
an economy of means not available in either Carbon or Cocoa.
Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@
Democracy: Two wolves and a sheep voting on lunch.
_______________________________________________
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