macosfswatch

When i fswatch a particular folder in mac , i get renamed is file for both addition and deletion of files in folder


I am monitoring a particular folder in mac os by giving in commandline

 fswatch -x /Users/syammala/folder

/Users/syammala/folder/posixGroup.xml Renamed IsFile

Whenever i add or delete a file i always get renamed is file. I want to differentiate the action, when i add and delete files


Solution

  • Updated Answer

    As you have now clarified that you are moving and deleting files using the Finder, it makes life more complicated because when you use the Finder it interacts with the Trashcan unlike when you use the Terminal and Unix commands. So, when you delete a file in Finder, it renames the file into the Trashcan which is stored in $HOME/.Trash.

    So, you effectively need to monitor the Trashcan as well as wherever you were planning on monitoring like this:

    fswatch -x FolderA $HOME/.Trash
    

    then you will see everything that is happening.

    Alternatively, disable the Trashcan - which I appreciate may not be acceptable however you do not provide much detail of your environment, so I don't know.

    To disable the Trashcan, remove the $HOME/.Trash directory and all its contents, and then create a file called $HOME/.Trash so that OSX cannot recreate its beloved Trashcan there. Do not do this if you don't understand it!

    cd
    rm -rf .Trash
    touch .Trash
    

    To later re-enable the Trashcan, do this:

    cd
    rm .Trash
    

    Original Answer

    You can do it like this with numeric flags.

    If you do this:

    touch FreddyFrog
    rm FreddyFrog
    
    touch BozoBrains
    mv BozoBrains SillyBilly
    rm SillyBilly
    

    you can monitor like this

    fswatch -xn `pwd`
    /Users/mark/tmp/FreddyFrog 514     # touch FreddyFrog
    /Users/mark/tmp/FreddyFrog 520     # rm FreddyFrog
    
    /Users/mark/tmp/BozoBrains 514     # touch BozoBrains
    /Users/mark/tmp/BozoBrains 528     # mv BozoBrains SillyBilly
    /Users/mark/tmp/SillyBilly 528     # mv BozoBrains SillyBilly
    /Users/mark/tmp/SillyBilly 520     # rm SillyBilly