Question

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?

Was it helpful?

Solution

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 "

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top