4

The problem, outside of AppleScript:

To witness the problem1, do the following:

  • Double-click on a folder that exists on the Desktop. Doing so will open this folder in Finder.app.

  • Return to the Desktop and double-click on that same folder again.

  • Instead of a second window being created, the previously created window will be brought to the foreground.


A workaround, outside of AppleScript:

So, what do you do if you want two Finder windows of the same folder?

A kluge exists:

Create a new Finder window by opening any other folder. From within this new window, now if you navigate to the desired folder, then you will successfully change this window to the desired folder, and have two windows of this folder.

To navigate to the desired folder within a new Finder window, any method will work:

  • Click on the folder, if it is bookmarked in the sidebar (if enabled, located at the left of the window).

  • Click on the folder, if it happens to exist in the path bar (if enabled, located at the bottom of the window).

  • Use the window's built-in search bar.

  • Or, simply navigate to the folder manually.


The problem, in AppleScript:

The following AppleScript code will open a folder in a new Finder window:

set targetFolder to POSIX file "/Users/Me/Desktop/MyFolder"

tell application "Finder"
    open targetFolder
    activate
end tell

In the exact same way that Finder behaves non-programatically (as defined above), if you run this code for a second time (without closing the previously created Finder window), then the previously created window will be brought to the foreground.


The desired AppleScript solution:

Here is the desired behavior:

  • If targetFolder already exists in any open Finder window (including any minimized Finder window), I would like the AppleScript to create a new window for the same targetFolder (i.e., a duplicate window).

Ideally, I would like the duplicate window to be created, without having to resort to the "trick" that I delineated above (i.e., opening an arbitrary other folder first, before opening the desired folder). However, I will understand if this is not possible (i.e., if the programmatic method must replicate the manual method).


1. I understand that this behavior is in no way a bug or a "real" problem. Apple clearly programmed this action deliberately; they probably determined that most people do not need or want redundant Finder windows.


OS X El Capitan, version 10.11.6.


5

Simple way to make a New Finder Window to the Desktop.


set myTarget to ((path to desktop) as text)

tell application "Finder" to make new Finder window to folder myTarget

From https://macscripter.net/viewtopic.php?id=36300

1
  • This does not completely answer the question asked, however, I up voted it because using make new Finder window to folder targetFolder in place of set target of (make new Finder window) to targetFolder in unlocked2412's answer then does everything that was asked in the OP. So for pointing in the right direction it was worth the upvote (IMO). – user3439894 Sep 1 '20 at 17:49
2

I think this code does what you want.

Code:

set targetFolder to POSIX file "/Users/Me/Desktop/MyFolder"

tell application "Finder"
    set finderFolder to item targetFolder
    set lstTargets to target of every Finder window
    if {finderFolder} is in lstTargets then
        set target of (make new Finder window) to targetFolder
    end if
end tell
3
  • This solution does exactly what I desire. It is my ideal solution; the script opens the folder without first having to open another folder. It also preserves my preferred Finder "View as" method (which happens to be List view). Finally, I've realized that an if statement is not even required to catch for the case of the folder already being open, because your set target of method functions properly, regardless. Thank you! – rubik's sphere Aug 31 '17 at 8:32
  • 1
    @rubik's sphere, Technically set target of (make new Finder window) to targetFolder first makes a new Finder window at the setting for New Finder windows show: in General of the preferences set in Finder and then changes to the value of targetFolder. So this is essentially doing the exact same thing as the described workaround, only automated. That said, if you replace that line of code with make new Finder window to folder targetFolder the window opened is directly to value of targetFolder. This is why I upvoted the new answer by S.Doe_Dude. – user3439894 Sep 1 '20 at 17:43
  • @user3439894 Your observation & analysis are 100% correct. I can see now that with unlocked2412's solution, the Finder window does in fact quickly switch folders. But with S.Doe_Dude's solution, the initial folder is the target folder and there is absolutely no switching, which is actually my desired result. For this reason, I've now made S.Doe_Dude's answer the accepted answer. Thank you for informing me! – rubik's sphere Sep 2 '20 at 0:32
0

This solution gets you where you wanna go, but it does use the workaround. I tried to set the "target" property as I created the window, but it had no effect. I left that part in the script but commented out for your reference.

set targetFolder to ((path to desktop) as text) & "testFolder:"

tell application "Finder"
    set aWin to make new Finder window --with properties {target:targetFolder}
    set aWin's target to targetFolder
end tell

I also tried it by calling on the command line with do shell script, but it had the same effect as you listed in "The Problem" above.

-2

Use the reveal command to avoid the behavior of the open command:

set targetFolder to POSIX file "/Users/Me/Desktop/MyFolder"
tell application "Finder"
    reveal targetFolder
    activate
end tell

Caveat: it always open the window in column view

1
  • I am very confused by this answer. On my computer, this code opens the parent folder of the targetFolder in the new Finder window. The targetFolder is simply highlighted/selected in the parent folder. Also, it does not "always open the window in Column view"; this code has no effect on the Finder view whatsoever. – rubik's sphere Sep 2 '20 at 2:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .