I have a task to create a way of monitoring a folder and files running on a MacOS 10.11 machine.

Basically what I want to accomplish is each time a new file is added to the folder send a notification to a monitoring URL and if after 30 minutes no files are added it will trigger an alert.

I am new to Mac OS programming but I have been tasked with this project and just looking for some suggestions on how to accomplish this

  • You didn't add details about the intended scope here. Folder monitoring can be done with Folder Actions and AppleScript/Automator, or with tools like Hazel, questions in this direction are on-topic. – nohillside Dec 19 '16 at 16:36
  • The intention is we have a folder that has incoming files and we want to know potentially when no new files have been moved to the folder in a specified amount of time. – Jonathan Alden Dec 19 '16 at 16:50
  • What will happen with the alert then, does it need to be shown to the user or does it need to trigger some other processing? – nohillside Dec 19 '16 at 17:12
  • It would send a notification to deadmanssnitch.com which would fire an email alert – Jonathan Alden Dec 19 '16 at 17:28
  • Then we would manually investigate why no files have been processsed – Jonathan Alden Dec 19 '16 at 17:28

I assume you intend to build something on your own. Things to look into here are

  • launchd: Allows programs/scripts to be run based on certain conditions. Of special interest for you is probably the WatchPaths parameter which allows to watch a path/directory for changes and triggers a program/script if necessary. There are race conditions involved here, but for your case you probably can catch them easily. The full format for launchd configuration files is available with man launchd.plist
  • Shell/bash scripting: The code to execute if a file arrives probably isn't too complex, so some basic scripts should be enough
  • How to send an email from command line?

On second thought, I would ignore the WatchPaths part completely. Just use launchd to run a shell script every 30 minutes (or whatever is appropriate) which, if no new file has arrived since when-ever, sends a notification to wherever.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .