Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Results 1 to 5 of 5
  1. #1
    kuroyume is offline Registered User
    Join Date
    Sep 2002
    Location
    Parker, Colorado
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New Finder given path (Carbon C++)

    Anyone have code (or links thereof) to do this - Open a Finder window to display a file/folder from an application? I understand that AppleEvent is involved here - but it sure would be nice to have some code that exemplified this.

    Please, no Cocoa, no Objective-C.

    Thanks

  2. #2
    Mikuro's Avatar
    Mikuro is offline Crotchety UI Nitpicker
    Join Date
    Mar 2005
    Posts
    2,832
    Thanks
    8
    Thanked 74 Times in 64 Posts
    My experience with Carbon is limited, but I know how to do this with AppleScript, and I'm sure there's a way to trigger AppleScript's from Carbon/C++. A little Googling returned some promising results on the matter:
    http://tishowicode.wordpress.com/200...ipt-in-carbon/


    Anyway, here's how it's done with AppleScript:
    Code:
    tell application "Finder"
    	activate
    	open folder "path:to:folder"
    	select item "filename" of window 1
    end tell
    You can also trigger AppleScripts from the shell:

    Code:
    osascript -e 'tell application "Finder"
    	activate
    	open folder "path:to:folder"
    	select item "filename" of window 1
    end tell'
    Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8
    MacBook Pro — 2.26GHz C2D, 8GB RAM — OS 10.6.8

    Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc

  3. #3
    kuroyume is offline Registered User
    Join Date
    Sep 2002
    Location
    Parker, Colorado
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much! I'll give the referenced code using the given AppleScript templates a try as soon as possible (lots of sleeve tugging in all directions at the moment).

  4. #4
    kuroyume is offline Registered User
    Join Date
    Sep 2002
    Location
    Parker, Colorado
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Must the "path:to:folder" be in the older HFS format (Macintosh HD:Applications:...) or can it also work with the newer format (/Applications/...)? I'm not getting a finder with the newer format but it may be either this or that it also requires the "/Volumes/Macintosh HD" be prepended (?). I am going to try each possible solution nonetheless.

    Thanks

  5. #5
    Mikuro's Avatar
    Mikuro is offline Crotchety UI Nitpicker
    Join Date
    Mar 2005
    Posts
    2,832
    Thanks
    8
    Thanked 74 Times in 64 Posts
    AppleScript takes paths in the classic Mac OS format, but if you need to pass it a Unix-style path, you can convert it from within AppleScript like so:

    Code:
    tell application "Finder"
    	activate
    	open folder POSIX file "/path/to/folder"
    	select item "filename" of window 1
    end tell
    Mac mini — 1.25GHz G4, 1GB RAM — OS 10.5.8
    MacBook Pro — 2.26GHz C2D, 8GB RAM — OS 10.6.8

    Useful programs: Privoxy, Butler, ffmpegX, VLC, Perian, Tofu, Wcalc

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •