How can I get the POSIX path of the Finder window that is currently at the top of its window list? Preferably with some kind of Cocoa framework but I am open for anything.
Background: I would need this because I want to make a selection of files matching a regex pattern, starting recursively from this path. The idea is to use
[[NSWorkspace sharedWorkspace] subpathsAtPath:thePath]
method to get all the descendants of this path, use "grep" in an NSTask (to avoid packaging a regex support framework) and use
[[NSWorkspace sharedWorkspace] selectFile:aFile inFileViewerRootedAtPath:thePath]
in a loop looping through an NSArray made from the entries returned by grep.
So far, I have looked at NSWorkspace, NSFileManager and NSApplication plus other keyword searches within the Xcode Documentation.
Thanks for checking out my question!
Andre
PS: I am not sure about the grep part, maybe I'll just slap RegexKit Lite in there...
You can probably ask the Finder this via an AppleScript.
This* one-liner works for me:
osascript -e 'tell application "Finder" to set myname to POSIX path of (target of window 1 as alias)'
*a modified version of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With