Make new Folder Action (Hot folder)

Although I can create a hot folder manually, I have tried to automate the process for myself and for others.


set targetFolder to choose folder with prompt "Choose folder you want make Hot folder"
set targetFolderPath to POSIX path of targetFolder

set folderActionScript to ¬
	choose file of type "com.apple.applescript.script" default location ¬
		(((path to library folder from user domain) as text) & ¬
			"Scripts:") as alias
set folderActionScriptPath to POSIX path of folderActionScript

tell application "System Events"
	set folder actions enabled to true
	set folderName to name of targetFolder
	if not (exists folder action folderName) then set folderAction to make new folder action at ¬
		end of every folder action with properties {name:folderName, path:targetFolderPath}
	make new script at end of every script of folderAction ¬
		with properties {POSIX path:folderActionScriptPath}
end tell