MacOS – Get path of open file in any application on Mac OS X

applescriptfindermacmacospath

I installed Afloat for Mac OS X and I really like that it has a shortcut to "Reveal Current File in Finder". This works for basically all applications written in Cocoa.

Can I use something like that, possibly applescript and the scripts menu, to get the path of the current open file, possibly in any application? I'd love to be able to set that to a shortcut key (I can manage that part).

Thanks!

Best Answer

tell application (path to frontmost application as text)
    set p to path of document 1
end tell

tell application "Finder"
    reopen
    activate
    set selection to {}
    set target of window 1 to POSIX file p
end tell
Related Question