Target of front window?

Is there a reason why this doesn’t work anymore ?

I just rebooted my machine, just in case…

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	try
		set myFolder to (the target of the front window) as alias
end tell

You left out the end try?

1 Like

Also, only Finder windows have targets, so the code will fail if the Finder’s front window is one of its other types, say, an information window or a clipping window.

1 Like

Sorry, that’s a copy paste error form a bigger piece of code.

tell application "Finder"
	try
		set myFolder to (the target of the front window) as alias
	on error
		beep
	end try
end tell

But as @NigelGarvey just wrote, I just realized that I had indeed an information window open and it might have been frontmost. Interesting because it is the very first time it happens to me and I’ve used that script for quite a long time.

It is a simple “create a text file in the front folder” that I then propose to open in an emacsclient instance.