File monitoring lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- havezet · 2011-11-29 00:13 I'm trying to capture file changes as reported by the operating system. It appears that I need to caption the FSEvents for that and that the way to do it is by using the API framework for FSEventStreamCreate. My problem is that I have no idea how I should set it up in Lazarus. Does anyone have a sample or can help me get started with this? ---------------------------------------------------------------------- havezet · 2011-11-29 10:12 A new day; a fresh mind; Here's a framework for FSEvents: Code: [Select]procedure FSStreamCallBack (                            streamRef: ConstFSEventStreamRef;                            clientCallBackInfo: UnivPtr;                            numEvents: size_t;                            eventPaths: UnivPtr;                            {const} eventFlags: {variable-size-array} FSEventStreamEventFlagsPtr;                            {const} eventIds: {variable-size-array} FSEventStreamEventIdPtr                            ); MWPascal; begin   ShowMessage ('changes happen for a reason'); end; procedure TForm1.StartFSEvents (AWatchPaths: Array of WideString);   var     AContext: FSEventStreamContext;     APaths: Array[0..1023] of CFArrayRef;     ACb: FSEventStreamCallback;     i, i2: Integer;     APath: String;   begin     if Assigned(FFStream) then       exit;     FillChar(AContext, SizeOf(AContext), 0);     AContext.info := self;     i2 := 0;     for i := Low(AWatchPaths) to High(AWatchPaths) do     begin       APath := UTF8Encode(AWatchPaths[i]);       APaths[i2] := CFArrayRef(CFSTR(PChar(APath)));       Inc(i2);     end;     ACb := @FSStreamCallBack;     FFStream := FSEventStreamCreate(                                    nil,                                    ACb,                                    @AContext,                                    CFArrayCreate(nil, @APaths, Length(AWatchPaths), nil),                                    kFSEventStreamEventIdSinceNow,                                    0,                                    kFSEventStreamCreateFlagNoDefer{kFSEventStreamCreateFlagWatchRoot}                                    );     if Assigned(FFStream) then     begin       FSEventStreamScheduleWithRunLoop(FFStream, CFRunLoopGetCurrent, kCFRunLoopDefaultMode);       FSEventStreamStart(FFStream);     end;   end;