Best way to scan a folder to see if its contents have changed

Discussion in 'Mac Programming' started by skunkworker, Sep 23, 2009.

  1. skunkworker macrumors regular

    Sep 9, 2007
    I have got a script that depends on scanning a folder's contents to see if it changes. I know that there is something in the 10.5 stuff with time machine that allows you to somehow do that. Does anybody know what the best way is?
  2. larkost macrumors 6502a

    Oct 13, 2007
    You really haven't told us much of what you want to do, so it is really hard to recommend something. The usual routes:

    1) Keep a log of what was in there last time, and manually poll for changes. This is about the worst route.

    2) Use launchd and a "KeepAlive" key for the watched path. This is probably the best route for a script... but depends on a number of things, and since you aren't sharing...

    3) Use the fsevents api to watch the folder. This will get you great notifications, but requires callbacks, so is difficult to do in almost all scripting languages (technically possible in Python, but really difficult).

    4) Use AppleScript "folder actions". I have never done this as they have a reputation of being flakey.
  3. HiRez macrumors 603


    Jan 6, 2004
    Western US
    Extremely. Don't go this route if you need reliability.
  4. skunkworker thread starter macrumors regular

    Sep 9, 2007
    I've got a script that needs to see if a folder's contents have changed in any way and if so recompress images. Do any of these things allow a unix shell script to check somehow at different time intervals. Like right now and in an hour but not to make a daemon.

Share This Page