Folder action script stops working on Catalina

Hi @all,

this folder action script below I am using in it’s extended version until (and including) Mac OS High Sierra where it runs perfectly.
It affects the appearance and position of the finder window of the folder it is attached to each time the folder is opened.
Now on a new Catalina based Mac it doesn’t work anymore. Not even in the simpelst way e.g. display a dialog on opening folder window.

As you can see the script holds an example for the shared folder window (folder name in German = “Geteilt”). I dropped all other folders to avoid any confusion.

Could someone help me out please?

Best regards
CCP

on opening folder window
	
	tell application "Finder"
		set screenResolution to bounds of window of desktop
		set scrWidth to item 3 of screenResolution
		set scrHeight to item 4 of screenResolution
		
		set winName to name of container window of folder this_folder
	end tell
	
	if winName = "Geteilt" then
		tell application "Finder"
			set properties of container window of folder this_folder to {current view:list view, toolbar visible:false, statusbar visible:true, sidebar width:0}
			set bounds of container window of folder this_folder to {0, 23, scrWidth / 4, scrHeight - distBottom}
		end tell
	end if
	
end opening folder

Model: MacBook Pro
Browser: Safari 605.1.15
Operating System: macOS 10.14

Hi, CCP.

I fixed 2 mistakes in your script:


on opening folder thisFolder -- EDITED
	set distBottom to 50 -- or, what you want value, ADDED
	tell application "Finder"
		set screenResolution to bounds of window of desktop
		set scrWidth to item 3 of screenResolution
		set scrHeight to item 4 of screenResolution
		set winName to name of container window of folder thisFolder -- FIXED the TYPO
	end tell
	
	if winName = "Geteilt" then
		tell application "Finder"
			set properties of container window of folder this_Folder to {current view:list view, toolbar visible:false, statusbar visible:true, sidebar width:0}
			set bounds of container window of folder this_Folder to {0, 23, scrWidth / 4, scrHeight - distBottom}
		end tell
	end if
end opening folder

NOTE: it is non-critical mistake as 2 mistakes above, but you can replace in 3 places (and is better) folder this_Folder with simply this_Folder, because Finder works with aliases fine, and this way you avoid unneeded folder reference converting.

This will make the script faster. It will work even faster if you get the container window of this_folder only once. So, all your folder action together:


on opening folder thisFolder
	set distBottom to 50
	tell application "Finder"
		set screenResolution to bounds of window of desktop
		set scrWidth to item 3 of screenResolution
		set scrHeight to item 4 of screenResolution
		tell (get container window of this_Folder)
			if (get name) is "Geteilt" then
				set properties to {current view:list view, toolbar visible:false, statusbar visible:true, sidebar width:0}
				set bounds to {0, 23, scrWidth / 4, scrHeight - distBottom}
			end if
		end tell
	end tell
end opening folder

Hi KniazidisR,

Thanks for your advices.
Unfortunately the script still doesn’t take any effect on the finder window when opening the folder.

I placed the script in these folders:
“MacBook:Library:Scripts:Folder Action Scripts:” and “~:Library:Scripts:Folder Action Scripts:”
Makes no difference …

When running a modified version of the script (see below) from within Skripteditor
the target window’s appearance and location on screen changes as expected.
There is one irritating aspect: It (sometimes) needs a delay between the first and the second command.

Would you mind to check out this one and the folder action version in your environment?
I’m running OS 10.15.4.

Thank you so much
CCP

property distBottom : 80
tell application "Finder"
	set screenResolution to bounds of window of desktop
	set scrWidth to item 3 of screenResolution
	set scrHeight to item 4 of screenResolution
	tell window 1
		if (get name) is "Geteilt" then
			set properties to {current view:list view, toolbar visible:false, statusbar visible:true, sidebar width:0}
			delay 1 -- if this is off the following "set bounds" will not take effect … sometimes ;)
			set bounds to {0, 23, scrWidth / 4, scrHeight - distBottom}
		end if
	end tell
end tell

It isn’t all steps. You should bind the script to the folder you want to do HOT folder. To do this:

  1. Right-click on the folder. Opens menu.
  2. Click “Folder Actions Setup…” → “Run service”–> “OK” if appears question for access. Opens Folder Actions Setup window with 2 sections. Left section is folders, right section is the script you want to attach to folder
  3. Set checkbox of your folder on the left section
  4. Attach the script I wrote on the right section. Use (+) to add your script. Set its checkbox too.

Only now you have HOT folder

Look here:

May you make a test:

on opening folder thisFolder
	-- was supposed to be an alias
	-- may you test what is really passed ?
	-- I would not be surprised if it's a «class furl» object
	set theClass to get class of thisFolder
	tell application "Finder"
		set theClass2 to class of thisFolder
	end tell
	
	display dialog "theClass is " & theClass & linefeed & "theClass2 is " & theClass2
end opening folder

Under 10.13.6, it returns :
theClass is alias
theClass2 is alias

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 8 avril 2020 16:05:01

@KniazidisR:

I did it … of course :wink:

@Yvan Koenig:
I can confirm it, both under 10.13.6 and 10.15.4.
But I cannot draw any conclusion from this – you can?
:wink:

Remain healthy!

OK.

As it pass an alias, try with :

on opening folder thisFolder
	set distBottom to 50
	tell application "Finder"
		set screenResolution to bounds of window of desktop
		display dialog "screenResolution : {" & my recolle(screenResolution, ", ") & "}"
		set scrWidth to item 3 of screenResolution
		set scrHeight to item 4 of screenResolution
		try
			tell (get container window of thisFolder) -- TYPO CORRECTED
				display dialog "Good, I entered the tell block" -- ADDED
				if (get name) is "Geteilt" then
					display dialog "Good, the folder name was recognized" -- ADDED
					set properties to {current view:list view, toolbar visible:false, statusbar visible:true, sidebar width:0}
					set newView to get current view
					display dialog "I hope that newView is list view. It is : " & newView -- ADDED							
					set bounds to {0, 23, scrWidth div 4, scrHeight - distBottom}
					set newBounds to its bounds
					display dialog "I hope that newBounds starts with {0, 23. It is : {" & my recolle(screenResolution, ", ") & "}" -- ADDED
				end if
			end tell
		on error errMsg
			display dialog errMsg
		end try
	end tell
end opening folder

#=====

on recolle(l, d)
	local oTIDs, t
	set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
	set t to l as text
	set AppleScript's text item delimiters to oTIDs
	return t
end recolle

#=====

If some dialog is(are) displayed, click the button OK and post the result here.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 8 avril 2020 19:56:39

Thanks Yvan.

The result of your script under 10.15.4:

  • dialog screenResolution is displayed
  • then error (translated): “The variable „this_Folder“ is not defined.”
    :rolleyes:

It’s logical I made a typo to try to generate an error.

tell (get container window of this_Folder) -- TYPO
tell (get container window of thisFolder) -- MUST BE

After posting this message I will edit the typo and add some instructions to get more infos.

I see a point which may be THE problem:

set bounds to {0, 23, scrWidth / 4, scrHeight - distBottom}

issue a floating value for the new width.
May you edit it as

set bounds to {0, 23, scrWidth div 4, scrHeight - distBottom}

which would issue an integer value.
Maybe Catalina isn’t satisfied by the floating value.

Now I know that the script really receive the event ‘open folder’ and it seems to receive correctly the name of the folder.

I hope that tomorrow I will read a message saying that everything works.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 8 avril 2020 22:23:33

Hi, ccp, again.

I fixed my script. Now it works as folder action too. It was the typo with name of the folder.


on opening folder thisFolder
	set distBottom to 50
	tell application "Finder"
		set screenResolution to bounds of window of desktop
		set scrWidth to item 3 of screenResolution
		set scrHeight to item 4 of screenResolution
		tell (get container window of thisFolder) -- FIXED the TYPO (was this_Folder)
			if (get name) is "Geteilt" then
				set properties to {current view:list view, toolbar visible:false, statusbar visible:true, sidebar width:0}
				set bounds to {0, 23, scrWidth / 4, scrHeight - distBottom}
			end if
		end tell
	end tell
end opening folder

@Yvan Koenig:
I didn’t know about replacing „/“ by „div“ to get an integer …
always used the addon „… as integer“ – thanks

@KniazidisR:
thanks, yes, it works … but still needs a delay between the first command (set properties)
and the second (set bounds); otherwise the second one is dropped.
This happens on both, 10.13 and 10.15.

Is there any way to get some kind of log to see what happens?
I mean if a folder action doesn’t show an error message on screen?
Something like displaying the console window in the background?

I did this already in an earlier version … it did not run then that’s why I splitted it … and still does not now …

Damn this Apple. Nowhere is it explained why the bounds property is not set stably in a single properties list … One of the reasons for this may be that the script’s access to this property is blocked while the 2nd, 3rd and 4th properties of this list set it. I can only advise setting a delay = 0.1 seconds. And also remove unnecessary checking on the folder name:


on opening folder thisFolder
	set distBottom to 50
	tell application "Finder"
		set screenResolution to bounds of window of desktop
		set scrWidth to item 3 of screenResolution
		set scrHeight to item 4 of screenResolution
		tell (get container window of thisFolder) -- FIXED the TYPO (was this_Folder)
			set properties to {current view:list view, toolbar visible:false, statusbar visible:true, sidebar width:0}
			delay 0.1
			set bounds to {0, 23, scrWidth / 4, scrHeight - distBottom}
		end tell
	end tell
end opening folder

Yep, I agree … especially with „Damn this Apple“ …
I don´t know if I would have bought the Macbook Pro if I would had known before how much effort this OS Catalina would take just to adapt things to keep them running … not to mention the dropping of 32bit apps … :mad:

On my side I use display notification

tell me to display notification "blahblah" & linefeed & (current date)

I didn’t do that in my proposal because to get that working we must define some parameters linked to Script Editor in the System Preferences pane named “Notifications” in French.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 9 avril 2020 16:05:52

Thank you both for your support – now it works … unfortunately with the delay … but okay

Stay healthy and have a good in spite of everything!

:slight_smile: