folder action this_folder

Having a problem creating folders inside the folder with action

This works


on adding folder items to this_folder after receiving added_items
	set userFolder to ("" & (path to current user folder))
	set inputFolder to ("" & userFolder & "testing")
	set outputFolder to my checkFolderCreate(inputFolder, "output")
	set joblogFolder to my checkFolderCreate(inputFolder, "JOBlogs")
	set errorFolder to my checkFolderCreate(inputFolder, "ERRORED")
end adding folder items to

--see if a folder exists and if not create
on checkFolderCreate(thePath, theName)
	set newPath to "" & thePath & ":" & theName
	if (my itemExists(newPath)) is false then
		tell application "Finder"
			make new folder in alias ("" & thePath) with properties {name:theName}
		end tell
	end if
	return newPath
end checkFolderCreate

-- check if an item exists
on itemExists(thePath)
	try
		tell application "Finder"
			alias thePath
			return true
		end tell
	on error errMsg
		return false
	end try
end itemExists

but this doesn’t


on adding folder items to this_folder after receiving added_items
	set inputFolder to this_folder
	set outputFolder to my checkFolderCreate(inputFolder, "output")
	set joblogFolder to my checkFolderCreate(inputFolder, "JOBlogs")
	set errorFolder to my checkFolderCreate(inputFolder, "ERRORED")
end adding folder items to

--see if a folder exists and if not create
on checkFolderCreate(thePath, theName)
	set newPath to "" & thePath & ":" & theName
	if (my itemExists(newPath)) is false then
		tell application "Finder"
			make new folder in alias ("" & thePath) with properties {name:theName}
		end tell
	end if
	return newPath
end checkFolderCreate

-- check if an item exists
on itemExists(thePath)
	try
		tell application "Finder"
			alias thePath
			return true
		end tell
	on error errMsg
		return false
	end try
end itemExists

keep in mind they are the same folder !

any thoughts or direction are appreciated

mm

Let me guess - it runs and runs and never stops until you kill it, right?

I believe you’re havingthe same problem I wrote a tutorial about. The short answer is you’re ignoring the fact that each time you create a folder in the folder with the folder action, it triggers the “on recieving items” event again. See the tutorial for a way around it.

Kevin,

I can sort of see your point but I have two problems with that first i that the first works !

second is that I check to see if the folder exists already and only creates a folder if it doesn’t exist so no infinite loop

Mike

The first one works because you’re not making the new folders in the target folder. In the second script, you’re adding folders to the target folder, which is supposed to run your folder action when there’s a new item and on and on. See?

Kevin,

I can assure you that they are the same location though to avoid the problem all together I have moved the folders out of “this_folder” and into the the current user folder :smiley:

but if you care to experiment you can make the test folder and apply the folder action script etc… etc…

thanks for your help

now time for a new question in a new post

Mike