Coder Social home page Coder Social logo

filesystemevents's Introduction

ARCHIVED

As like noted below, this project has been archived, and no longer be maintained. For new projects, I recommend you to use my new implementation.

README

2014/11/13 2015/01/17 2015/04/04 2016/09/25 Hoon H.

Carthage compatible

Provides dead-simple access to FSEvents framework for Swift. Low level core is written in Objective-C due to lack of support from Swift. (lacks some flags, lacks C-callback function)

How To Use

First, you need to add this framework to your Xcode project. If you're not sure how to add this framework to your existing Xcode project, please see this video posting.

Here's a minimal example code which waits for events and prints them. This single statement does everything all needed jobs to setup. Just keep the created object as long as you want to receive the events.

	import Cocoa
	import EonilFileSystemEvents

	@NSApplicationMain
	class AppDelegate: NSObject, NSApplicationDelegate {

		@IBOutlet weak var window: NSWindow!
		
		let	s1 = FileSystemEventMonitor(
			pathsToWatch: [
				"~/Documents".stringByExpandingTildeInPath, 
				"~/Temp".stringByExpandingTildeInPath],
			latency: 1,
			watchRoot: true,
			queue: dispatch_get_main_queue()) { (events: [FileSystemEvent])->() in
				println(events)
			}
	}

If you want to stop monitoring, just remove all the strong references.

	var m: FileSystemEventMonitor? = FileSystemEventMonitor( /* arguments omitted */ )
	// Now it started.

	m = nil 
	// Now it stopped. Because it's dead. 

Please take care that object reference can be shared in Swift, so you need to ensure no other object to reference the monitor object. If you're not familiar with reference-counting, please see this: Automatic Reference Counting

See TestdriveApp target for another fully fledged Swift example. The example app starts monitoring when it becomes active, and stops monitoring when it becomes inactive. Try it!

Explanation

Use FileSystemEventMonitor class. Required informations are all noted as comments. Create it, and monitoring will start immediately. Deallocate it to stop monitoring. (RAII semantics) Supplied callback block will be notified on specified event.

Unfortunately, as Swift does not support static library target, you cannot link this as a library to a command-line programs currently. So examples had to written as an AppKit application target.

For Objective-C programs, use EonilFileSystemEventStream class. Required informations are all noted as comments. This class follows strict Objective-C conventions, so should be straightforward. It is unclear how long I will keep the Objective-C version.

Note

This library requires macOS 10.10 to run and Xcode 8.0 to build.

I also have another version of file-system watcher library. It's not extensively tested, but you can check it out if you're interested. This is clean-slated Swift3 implementation with directing binding to C API without Objective-C stuffs.

License

This library is written by Hoon H. and licensed under "MIT License".

filesystemevents's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

filesystemevents's Issues

Ability to stop/close Event Stream

I'd like to use this framework in a multi-document app, where each document window tracks one or more paths using an event stream.

When a window is closed, I would like to stop/close that event stream.

I'll look into it, but am very new to Mac OS X / Cocoa / Swift / Obj-C so will be an uphill struggle....

Temp file stream doesn't detect renaming/modification of file.

Basically, I am shooting images and the studio software I am using ingests ~25MB raw files. The software first create a "temp.{FileName}.{Extension}" that it streams data to. When it's done, it renames the file to "{FileName}.{Extension}". I am not getting an event callback for when it renames/modifies the file.

Any help would be great,

Thanks.

Getting "No such module 'EonilFileSystemEvents" error

Thank you for creating this project!

I am unable to link the module. Here are the steps I took:

  1. created a new swift cocoa project in Xcode called "Simple Test"
  2. copied "Project" directory from "FileSystemEvents-master" to the new project
  3. followed the "A proper way to add a subproject to another Xcode project."
  4. cleaned and built new project.

I get 1 error:
".../Simple Test/Simple Test/AppDelegate.swift:10:8: No such module 'EonilFileSystemEvents'"

Do I need to add a bridging header? Modify header and/or framework search paths?

make FileSystemEvents framework available via cocoapods

@eonil thank you for EonilFileSystemEvents ๐Ÿ‘
To make it easier for other people to include and use this framwork in their projects It would be great to add it to cocoapods. I played around with a local podspec for EonilFileSystemEvents trying to link against my project. As I am a total Xcode/swift noob I did not get very far.
If you generally like the idea of cocoapods, and have not objections against adding a podspec I would be happy to send a pull-request with what I currently have.

Use FileSystemEvents in my project

Hi Eonil, I am building a Mac Application and I have a requirement which meets your project. So how can I use your project as a library in my project ??

Please show me a way :)

how to know if the file is modified only

if i print event i am getting all the changes but i want to have call back only if the file is modified(ItemModified)

path: xxxxxxxxxxxxxx, flag: ItemRemoved, ItemRenamed, ItemModified, ItemChangeOwner, ID: 33344323), (path: xxxxxxxxxxx, flag: ItemRenamed, ItemFinderInfoMod, ItemXattrMod, ID: 33344417)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.