1

I had implemeted file watcher part using SCEvents : https://github.com/mz2/SCEvents It is notifying me when file is created,modified,deleted or renamed like this:

2014-02-11 16:08:38.725 TestSCEvent10-2[2995:403] SCEvent { eventId = 3182336, eventPath = /Users/user1/Desktop, eventFlags = 131328 }

Its returning the path of parent directory. How should i get full path of modified file?

4
  • I have temporally removed my answer which suggested placing the path pointer in the description method. Actually looking at the code again I do not think that will work as I think the eventPath is pointing to the path which may mean the watch path. I will look at it when I get back to a mac and see if I can find away to add it.
    – markhunte
    Feb 11, 2014 at 12:41
  • I have added my answer back with what I think and has in my tests worked.
    – markhunte
    Feb 11, 2014 at 14:49
  • @markhunte Which of these should be left stinging? this one or the one that was asked here? This one seems cleaner in the answer - but we could edit the other if this gets closed as dupe...
    – bmike
    Feb 11, 2014 at 17:19
  • @bmike I think your right this one. Thanks
    – markhunte
    Feb 11, 2014 at 17:23

1 Answer 1

4

In the SCEvents.m file

Add the FSEventStreamCreateFlags Constant kFSEventStreamCreateFlagFileEvents to the FSEventStreamCreate flags as shown here:

static FSEventStreamRef _create_events_stream(SCEvents *watcher, CFArrayRef paths, CFTimeInterval latency, FSEventStreamEventId sinceWhen)
{
    FSEventStreamContext callbackInfo;

    callbackInfo.version = 0;
    callbackInfo.info    = (void *)watcher;
    callbackInfo.retain  = NULL;
    callbackInfo.release = NULL;
    callbackInfo.copyDescription = NULL;

    return FSEventStreamCreate(kCFAllocatorDefault, 
                               &_events_callback,
                               &callbackInfo, 
                               paths, 
                               sinceWhen, 
                               latency, 
                               kFSEventStreamCreateFlagUseCFTypes | kFSEventStreamCreateFlagWatchRoot |kFSEventStreamCreateFlagFileEvents);
}

kFSEventStreamCreateFlagFileEvents

Request file-level notifications. Your stream will receive events about individual files in the hierarchy you're watching instead of only receiving directory level notifications. Use this flag with care as it will generate significantly more events than without it. Available in OS X v10.7 and later.

Declared in FSEvents.h.

Discussion

Flags that can be passed to the FSEventStreamCreate...() functions to modify the behavior of the stream being created.

The will change the eventPath to output the full file path.


UPDATE:

Also in the In the SCEvents.m file is the Latency Setting.

// Constants static const CGFloat SCEventsDefaultNotificationLatency = 3.0;

It may be set to 3.0. I set mine to 8.00.

"latency" parameter that tells how long to wait after an event occurs before forwarding it; this reduces the volume of events and reduces the chance that the client will see an "intermediate" state, like those that arise when doing a "safe save" of a file, creating a package, or downloading a file via Safari "

6
  • Hi.. The SCEvents is notifying me for everything. I want only notification when file is crated,deleted,modified and renamed. And also folder is created,deleted,renamed.. Its notifying correctly but when file is created its giving two events. For rename it's ok i.e. previous path and new path with new file name. Is thr any thing so that i will get only specific file and folder related notification? I have tried by making some modification in SCConstants.h file by setting enum but still its giving me other notification. Can u please give me guidance for this.. Thanks in advance... Feb 12, 2014 at 3:37
  • Hi, That was why I put the apple quote in the answer. Have a look at changing the Latency setting in SCEvents.m - static const CGFloat SCEventsDefaultNotificationLatency = 3.0 and read the FSEvent docs so you gain an understanding of whats going on. This is all I am doing to find the answers
    – markhunte
    Feb 12, 2014 at 7:39
  • I don't know about Latency setting.. I tried by changing value of latency but not getting proper output.. My question is its setting SCEvents flags i.e. enum in SCConstants.h but after running application its returning flags value like 131328,133120,69632,71680, 102656 etc.. not returning value which is set at SCConstants.h.. What is the reason? What modification is required? Any help and guidance is most important for me... Please help me... Feb 17, 2014 at 4:48
  • See my update. But as far as I am aware you do not need to touch the SCConstants.h file?. I have looked at this all of 20 minutes to get your initial answer without ever seeing it before. And now 25 minutes. I would like to help you further BUT you need to help yourself first. Read the docs as suggested. Try setting the Latency as suggested. You could try and create a method that distinguishes between the event codes and give you a value that is human readable. And if you need be ask a new question do it as a New Question because the comments is not the place to ask what you are now asking.
    – markhunte
    Feb 17, 2014 at 5:20
  • Thanks for your valuable time.. I will make changes as per your instructions and will read that docs also.. Feb 17, 2014 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.