• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to launch Finder with given directory from Carbon app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to launch Finder with given directory from Carbon app


  • Subject: Re: How to launch Finder with given directory from Carbon app
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Thu, 12 Feb 2009 09:52:43 +0100


Le 12 févr. 09 à 01:00, Philip Aker a écrit :

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.


And what if the user choose to open folder with something else than the Finder (Path Finder) ?
It's like using OSA and Safari to open an URL. The user may have choosed something else than Safari as the default browser. _______________________________________________
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
  • Follow-Ups:
    • Re: How to launch Finder with given directory from Carbon app
      • From: Philip Aker <email@hidden>
References: 
 >How to launch Finder with given directory from Carbon app (From: Dieter Oberkofler <email@hidden>)
 >Re: How to launch Finder with given directory from Carbon app (From: Philippe Casgrain <email@hidden>)
 >Re: How to launch Finder with given directory from Carbon app (From: Ken Thomases <email@hidden>)
 >Re: How to launch Finder with given directory from Carbon app (From: Philip Aker <email@hidden>)

  • Prev by Date: Re: Interface Builder Hangs
  • Next by Date: query on stack trace
  • Previous by thread: Re: How to launch Finder with given directory from Carbon app
  • Next by thread: Re: How to launch Finder with given directory from Carbon app
  • Index(es):
    • Date
    • Thread