New Finder given path (Carbon C++)

kuroyume

Registered
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
 
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/2007/11/07/run-applescript-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'
 
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).
 
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
 
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
 
Back
Top