Create a New Window in the Finder if None Are Open

How do I create a new window in the Finder if they is none? I've tried (which in this screenshot is deactivated because it does the wrong thing)

This only creates a new window if there is already one, not if none exists.

The following, which seems like the correct logic, does nothing. Thanks for any help. (Seems like this should be an OS option, but I don't see it. El Capitan)

Hey KBM,

Hmm…

Keyboard Maestro is seeing WINDOWCOUNT as 1 when NO windows are open in the Finder.

I suppose it could be counting the Desktop as a window, but we’ll have to wait for Peter to weigh-in on that.

You can use an Execute an AppleScript action and this script to work around the issue.

set winTarget to path to documents folder
tell application "Finder"
  if (count of windows) = 0 then
    open winTarget
  end if
end tell

* The target window can easily be changed if you want something other than Documents.

-Chris

2 Likes

Thanks. That did the trick.

OT: I don’t see a place to check off that this is the right or good answer or helped me.

Hey KBM,

Good deal.

See the little heart icon in the toolbar beneath the post? That's the LIKE button.

/Users/yourUserName/

I'd say it's because it's too easy to confuse the other user directories:

/Users/
/usr/

$HOME very specifically refers to the current user's home directory

Home Directory on Wikipedia

I reckon too that “Home Directory” is a more comfortable idiom for most folks to use when they're fooling with an alien contraption like a computer.

-Chris

1 Like

Translation footnote – a JavaScript for Applications version.

var fi = Application('Finder'),
    ws = fi.windows;

if (ws.length) ws[0].activate();
else {
    var a = Application.currentApplication(),
        sa = (a.includeStandardAdditions = true, a);

    fi.open(
        sa.pathTo('documents folder')
    );
}

2 Likes