4

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

MacDeveloper
  • 1,334
  • 3
  • 16
  • 49
  • What is `fswatch`? It's not a command that's built into OS X. How about you ask whoever provides it? In any case, this isn't a question about programming or developer tools, so isn't appropriate for StackOverflow. – Ken Thomases Aug 05 '15 at 09:09
  • fswatch is cross platform monitor which uses FSevents in MAC OSX. As far as i know when we give this in commandline, it displays events occured on particular Folder location we mentioned. But for addition and deletion i get same message displayed. I want to know can we do any programatical changes to get what action is performed actually on the folder – MacDeveloper Aug 05 '15 at 09:29
  • You're looking to modify `fswatch`'s code? Then you need to show the code that it currently uses and ask some specific question about it. – Ken Thomases Aug 05 '15 at 09:34
  • Where can i get fswatch code to modify. If some one can suggest that will it come under programming question? please help me to solve this issue – MacDeveloper Aug 05 '15 at 09:43
  • 2
    I know this is four years too late, @Dutt, but fswatch is available on GitHub, under a GPL license. Download and modify your heart out. https://github.com/emcrisostomo/fswatch – Jason Conrad Jan 23 '19 at 20:20

1 Answers1

4

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • When i move files from command line and delete files from command line i am getting the same 528. And also when i drag and drop files in to the folder and outside the folder i am getting this same 528. I want to distinguish this each action in the folder – MacDeveloper Aug 05 '15 at 11:15
  • So if you repeat the exact commands I showed, you always get 528, never 514, never 520? Is that correct? What version of OSX are you using? – Mark Setchell Aug 05 '15 at 11:49
  • We do get 514 when we create as touch file and 520 for rm file. What i am saying is for drag and drop and deletion we are always getting 528. – MacDeveloper Aug 05 '15 at 11:53
  • Ok, my guess is that when you do GUI drag&drop operations, it actually **moves** the files to the Trashcan, so deletions and renames appear the same. Try disabling the Trashcan for the volume temporarily to check. – Mark Setchell Aug 05 '15 at 12:18