folder action opinions please!

Hi all,

I currently have a folder action that sends an email when files/folders are added to it. This works fine but I’m now receiving DMG files and would like to mount the DMG, move its contents back into the folder that’s running the folder action and email a list of its contents and then delete it. I can do this, but obviously when I add the files back to the folder that’s running the folder action it triggers it again, so I’m looking for ways to stop this. Creating another folder for the files to be added to is not an option as this if an FTP folder and would mean me giving new details to internal and external users.

I have 2 ideas of how to tackle this problem but I’m not sure which is the best or if you have any better ones!.

idea 1:
When a DMG file is added to the folder, write a text file containing a list of contents of the DMG, when the contents of the DMG are added back to the folder read the text file and if the name of the added item is contained in the list do nothing apart from remove the name from the text file.

idea 2:
When a DMG file is added to the folder, disable the folder action until all of the contents have been added back to the folder, then re-enable the folder action.

Idea 2 is the simplest and requires the least amount of code, the only flaw I can see with this is, if a file is added to the folder at the same time as I disable the folder action it won’t be triggered. This may seem a small detail but I like my scripts to be as flawless as possible.

I appreciate any comments

Thanks,
Nik

Given that you don’t want to create an alternate folder, but are having retriggering problems with the Folder Action, I’d suggest a stay-open on-idle application (backgrounded) that watches the folder and manages your workflow when it discovers changes. Even more sophisticated (and more efficient) is to run a launchd agent that watches the folder and triggers your script
whenever there are changes.

There’s a tutorial by Craig Smith to explain how to use launchd: Using launchd with AppleScript to Access a Flash Drive Automatically

Hi Adam,

Thanks for your reply, The reason that I hadn’t used a Stay Open app is that I would have to list the directory and check for any files that had been added, the only way I could tell if a new file had been added is if I logged the names of files that had already been processed in a text file or something like that, this file would obviously be increasing in size. I know the obvious answer would be to process the files and then move them into another directory but unfortunately I’m working with the restrictions that have already been set i.e. the added files must remain in the folder they’ve been added to.

Thanks,
Nik

The only way to get rid of the infinite loop and keep the files in the same folder is
to add a specified prefix to the files and filter this prefix in the handler

Thanks for your suggestion Stefan but I need to keep filenames as they have been originally supplied(a lot of restrictions on this one).

I have gone with my first idea.
Mount the DMG and create a list of its contents and write this to a text file.
copy the contents of the DMG to the container of the DMG
Unmount the DMG and then delete it
Email a list of the DMG contents

When the folder action is triggered it reads the text file and compares the filename of the added item to the paragraphs of the text file, if there’s a match then do nothing with the file just delete the name paragraph from the text file, however if the filename is not in the text file then send an email notifying delivery of the file.

Thanks again,
Nik