Hard won knowledge for us noobs - folder actions

I am posting this for the noobies and the non-programmers who frequent this forum to possibly save you the time and frustration that I just went through to find out something so simple, so maddeningly stupid that I am almost too ashamed to admit it happened to me. Almost but not quite (I have little shame).

Okay, the script below is pretty simple, it’s function is to add an inbox and an outbox to a customers folder (via duplication so I can keep that swell custom icon on them) in my FTP directory then attach a script to each of those folders. Really simple, except it wasn’t. I knew to put the script that I wanted to attach to the FTP folder (the one below) and the scripts to be attached to the inbox and outbox respectively in the Folder Action Scripts folder so they actually run (thanks Stefan) But here’s what I didn’t know - the scripts need to have the .scpt extension at the end in order to run. After re-writing my script two dozen times I finally started looking at the properties of the script, I mean what else was left? I noticed that when I right-clicked the FTP folder the context menu did not have either the Remove a folder action> or the Add a folder action> entry but when I did the same to a folder I knew worked properly I saw that the ONLY difference was that the script had the .scpt extension.

Now maybe I’m wrong and this is just a fallacious assumption on my part, and I hope that one of the regulars will correct me if that is the case, but this solved my problem. I never thought that I’d have to pay attention to the extensions of any of my files on a Mac, but I guess this is the exception to that rule.

on adding folder items to this_folder after receiving added_items
	tell application "Finder"
		activate
		set lFTPFolder to this_folder as Unicode text
		set lCustomerFolder to added_items as Unicode text
		set lDMTFolder to ((path to applications folder) & "Application Folder Name:") as Unicode text
		my sDuplicateFolder(lCustomerFolder, lDMTFolder, "Inbox")
		my sDuplicateFolder(lCustomerFolder, lDMTFolder, "Outbox")
		my sAttachScripts(lCustomerFolder, "Inbox")
		my sAttachScripts(lCustomerFolder, "Outbox")
	end tell
end adding folder items to

--> Duplicate folder

on sDuplicateFolder(lCustomerFolder, lDMTFolder, lBox)
	tell application "Finder"
		try
			set lBoxPath to (lDMTFolder & "Components:Folders:" & lBox) as Unicode text
			duplicate lBoxPath to lCustomerFolder
		on error msg
			display dialog "ERROR: " & msg with icon stop
		end try
	end tell
end sDuplicateFolder

--> Attach script to folder

on sAttachScripts(lCustomerFolder, lBox)
	tell application "System Events"
		try
			attach action to (lCustomerFolder & lBox) as Unicode text using lBox & ".scpt"
		on error msg
			display dialog "ERROR: " & msg with icon stop
		end try
	end tell
end sAttachScripts

Hope this saves someone else some headaches.

Imagine my surprise when I discovered that the problem may not lay in whole or in part with the extension, because what I have since noticed is that every time I shut my machine off and turn it back on all of my folder actions have become disassociated with their folders.

They are actually still attached, I can see them in the Folder Actions Setup window, but the same problem remains - the context menu does not have either the Remove a folder action> or the Add a folder action> entry and of course neither of the scripts will run.

Is there a preference in the Library or someplace I can delete that will reset my folder actions back to factory? I suspect a corrupt preference file but don’t know what to trash safely.

Thanks in advance for any help rendered.

Hi,

Check System Preferences and see if System Events is a login item. If not, disable folder actions and reenable it. Now check if System Preferences has System Events as a login item. System Events runs folder actions.

gl,

Thanks for the info Kel. Last night I decided to throw caution to the wind and went into my “Users:eric:Library:Preferences:” folder and deleted both the com.apple.FolderActions.plist and the com.apple.FolderActionsSetup.plist files. It seems to have worked but in the future I will use your suggestion, it seems less likely to result in some kind of catastrophic system failure :lol: .