Open same folder in new Finder window. Broken now?

I’m not sure what happened here… I had this script (saved as an ‘Application’) that would open a new Finder window that was looking into the same Finder window that was already open. However, something’s gone wrong. It doesn’t work anymore. Not sure what could’ve broken it. Here’s the script. Running on a 2012 MBP w/10.8.2

try
	tell application "Finder"
		activate
		set this_folder to (the target of the front window) as alias
		set {x1, y1} to position of front window
		make new Finder window to this_folder
		set position of front window to {(x1 + 50), (y1 + 150)} --This offsets the new window more than the average Finder tiling does
	end tell
end try

Any help would certainly appreciated as this is something that I use quite a bit”or at least DID use quite a bit.
Thanks!

Hello.

Maybe the reason that your app doesn’t work anymore, is that it ran under faulty condidtions, and the applet got corrupted, somehow. Maybe you can only open it, and edit it, save it, and run it. :slight_smile:

I have however made a slightly more robust version for you: pleae try the one below, if it doesn’t work, open Console.app, and see if there is any logfile named NewFinderWin. If it is, open it, and please post the error message.

I have changed any references to a window, into Finder window, since there are many window classes but just one Finder window class. I have also, incorporated a test for if any finder window are open, and if it isn’t, it opens a window to the desktop.

try
	tell application "Finder"
		activate
		set fwct to count every Finder window
		if fwct > 0 then
			set {i, made_win} to {1, false}
			repeat while i ≤ fwct
				try
					set this_folder to (the target of Finder window 1) as alias
					set {x1, y1} to position of Finder window 1
					make new Finder window to this_folder
					set position of Finder window 1 to {(x1 + 50), (y1 + 150)}
					--This offsets the new window more than the average Finder tiling does
					set made_win to true
				end try
				if made_win then
					exit repeat
				else
					set i to i + 1
				end if
			end repeat
			if not made_win then
				make new Finder window to folder "Desktop" of home
			end if
		else
			make new Finder window to folder "Desktop" of home
		end if
	end tell
on error e number n
	logit("Oops:" & e & " " & n, "NewFinderWin")
end try

to logit(log_string, log_file)
	do shell script ¬
		"echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬
		"\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit

Edit

I have updated it to also consider that Spotlight windows doesn’t have a target folder, this is a quite ususal circumstance for such scripts to fail (by experience :slight_smile: ).

It could probably have been done in a more elegant way, but not at this hour.

Awesome! Thanks for taking the time. Running great again for me now.

I’m wondering though… I didn’t mean to ‘hide’ the truth before, but I never mentioned that the prior version of my “Application” existed (as it does now again) on Dropbox. I’m curious if the act of syncing it up, at some point caused the corruption? Anyway, the good news is I’m back in action.

Thanks again for your help!

Hello McUsr

it seems that you forgot what Nigel taught us two or three days ago. :wink:


to logit(log_string, log_file)
	do shell script ¬
		"echo `date '+%F %T: '`\"" & log_string & ¬
		"\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit

%F does the same thing than the llllllong %Y-%m-%d

KOENIG Yvan (VALLAURIS, France) samedi 6 juillet 2013 11:44:12

One possibility is that the Finder’s ‘front window’ at the time you run the script isn’t a ‘Finder window’ (one showing the contents of a folder), but one of its other types such as a ‘clipping window’ or an ‘information window’ or the ‘preferences window’. These all come under the general class name ‘window’. You can allow for this by explicity specifying the ‘front Finder window’ as the one of interest:

try
	tell application "Finder"
		activate
		set this_folder to (the target of the front Finder window)
		set {x1, y1} to position of front Finder window
		make new Finder window to this_folder
		set position of result to {(x1 + 50), (y1 + 150)} --This offsets the new window more than the average Finder tiling does
	end tell
end try

It was actually McUsr who brought it to my attention! :slight_smile:

Hello

The logit handler in the form I use it gives a better clue to a new user about what it does in its present form, and I am not going to update it. I really hadn’t thought it through, when it comes to clippings that works, I tend to just paste them in. :slight_smile:

If I change it, then I’ll have to comment it, so if the purpose was to create a smaller handler, then the handler becomes longer. I am not saying that the one approach is better than the other, but in Nigel’s handlers, there the date, is the pivotal item, here it is a secondary thing.

And the handler, that is brilliant, wasn’t written by me originally, I deleted the author by mistake one day, when I removed comments from something. And I haven’t refound his name since then.