Skip to content

@seanlilmateus /filesystem_events.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Handling Filesystem Events with GCD and Macruby
#!/usr/local/bin/macruby
framework 'Foundation'
include Dispatch
#``O_EVTONLY`` is defined as ``0x8000`` in the OS X header files.
# instead of RDONLY flag I use the O_EVTONLY flag to open() the file, otherwise we'll prevent the
# volume that the file is on from being unmounted.
O_EVTONLY = 0x8000
file = File.open("/path/to/config.plist", O_EVTONLY)
q = Queue.new('org.macruby.gcd_filesystem_events.sources')
type = Source::VNODE
option = Source::VNODE_EXTEND
# hold the changes
@oldFile = file.read
Dispatch::Source.new(type, file, option, q) { |src|
src.suspend!
puts "changed data: #{src.data} #{src.handle.path}" if src.suspended?
src.resume!
showChanges
# to cancel
src.cancel!
}
# show last state and New State
def showChanges
file = File.open("/path/to/config.plist", File::RDONLY).read
warn @oldFile
puts file
puts "_________________________________"
@oldFile = file
end
NSRunLoop.currentRunLoop.runUntilDate(NSDate.distantFuture)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.