# New Finder given path (Carbon C++)



## kuroyume (Feb 12, 2008)

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


----------



## Mikuro (Feb 12, 2008)

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:

```
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:


```
osascript -e 'tell application "Finder"
	activate
	open folder "path:to:folder"
	select item "filename" of window 1
end tell'
```


----------



## kuroyume (Feb 12, 2008)

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).


----------



## kuroyume (Feb 13, 2008)

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


----------



## Mikuro (Feb 13, 2008)

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:


```
tell application "Finder"
	activate
	open folder POSIX file "/path/to/folder"
	select item "filename" of window 1
end tell
```


----------

