Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I often use open . to open the current folder from Terminal.app. From time to time this doesn't work. The reason is that the folder in question is already open in some other Finder window on some other Space.

Hunting down this Finder window by searching all spaces takes too long. Neither do I really want to go a different space. I just want to open a new Finder window right there on the current space, regardless of other Finder windows open anywhere else.

I tried open -n . but this just hangs.

share|improve this question
    
As I don't think -n would ever work with finder, I suggest using the "App Expose" mouse gesture. If done from finder, it will show all open finder windows. –  demure Jun 5 '13 at 13:59
add comment

1 Answer 1

up vote 3 down vote accepted

You might use a script like this:

#!/usr/bin/osascript

tell application "Finder"
    make new Finder window to POSIX file (system attribute "PWD")
    activate
end tell

The script above always creates a new window. This wouldn't create a new window if a window with the same name already exists on the current space:

#!/usr/bin/osascript

launch application "Finder"
set pwd to system attribute "PWD"
set text item delimiters to "/"
tell application "System Events" to tell process "Finder"
    set w to windows where name is text item -1 of pwd
    if w is {} then
        tell application "Finder" to make new Finder window to POSIX file pwd
    else
        perform action "AXRaise" of item 1 of w
    end if
    set frontmost to true
end tell

System Events only includes windows on the current space.

share|improve this answer
    
The first script works splendidly! I named it reveal and put it in /usr/local/bin. –  Alexander Ljungberg Jun 5 '13 at 16:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.