Newbie: Folder Actions stop working

Hi all,

I’ve setup some folder actions, basically two scripts the first says that a new file has been added to a folder, so that I’m alerted even if the screen saver is active. The second then moves the file to another folder after a set time.

Every now and then the folder actions stop working.

Any ideas why this happens.

Craig

I assume the files are being added over a network connection and that your machine may sleep. You may have better luck if you set the Energy Saver Panel setting for the CPU to never.

The energy saver is already set to never. The machine is used as a web server, the clients connect to the machine using web dav, drop the files in folders that are access controlled using realms. Its these folders that have the folder actions set.

Craig

This seems to be a problem with webdav’d and ftp’d files - System Events doesn’t always trigger the folder action as it should. (If you search, you’ll find other examples). The solution proposed is to abandon the FA approach and instead write the same functionality into a stay-open script with an on idle handler set to a reasonable repeat. The idle handler is scripted to compare the contents of the folder to the contents of one “look” ago on every repeat, and trigger on the changes. Since we rarely hear back from folks who switch to this approach, I surmise that it works for them.

Adam thanks for the help so far.

These are the two folder actions that i’m using. The first is the apple “add new item alert” script with the say in the begining.

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items
	
	say "New File in guest folder"
	
	try
		tell application "Finder"
			--get the name of the folder
			set the folder_name to the name of this_folder
		end tell
		
		-- find out how many new items have been placed in the folder
		set the item_count to the number of items in the added_items
		--create the alert string
		set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
		if the item_count is greater than 1 then
			set alert_message to alert_message & (the item_count as text) & " new items have "
		else
			set alert_message to alert_message & "One new item has "
		end if
		set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
		set the alert_message to (the alert_message & return & return & "Would you like to view the added items?")
		
		display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
		set the user_choice to the button returned of the result
		
		if user_choice is "Yes" then
			tell application "Finder"
				--go to the desktop 
				activate
				--open the folder
				open this_folder
				--select the items
				reveal the added_items
			end tell
		end if
	end try
end adding folder items to

Then the second script starts and moves the files after 2 hours.

on adding folder items to thisFolder after receiving theAddedItems
	
	delay 7200
	
	
	tell application "Finder"
		
		move theAddedItems to folder "Server HD1:Users:Shared:Folder Name Archive:Guest Folder Archive"
		
	end tell
	
end adding folder items to

Do I need combine them into 1 script (didn’t seem to work when I tried this). Also do I just save them as an application with stay open and startup screen checked? Do I need to put them in a specific location?

I assume you know you can’t save them as is. An idle handler has this structure:

on run
	-- do stuff - this runs when the application is started to get the first snapshot. 
	-- Here you could create a list of all the files already in the folder and perhaps their modifation dates.
end run

on idle
	-- In this section, you periodically check names and dates of the file in the folder and compare them to the previous check. If one has changed you do your thing.
	return 60 -- do this every 60 seconds, or whatever interval you want. To deal with your second script's function, I would count cycles of this time (set numchecks to numchecks + 1) and then test this against some number at which they should be moved anyway. When you run the handler to do that, you also reset your counter.
end idle

on quit
	-- do stuff - assumes something in the idle handler would cause the application to quit from within or that it has been quit and you want to write out your list to a prefs file before quitting for example.
	continue quit
end quit

Adam,

I know nothing!!

I was directed to folder actions via the apple support a couple of weeks ago. Then yesterday found this forum.

I’m looking at your last post and thinking “I haven’t got a clue”

Craig