Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Handling Filesystem Events with GCD and 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 ="/path/to/config.plist", O_EVTONLY)
q ='org.macruby.gcd_filesystem_events.sources')
type = Source::VNODE
option = Source::VNODE_EXTEND
# hold the changes
@oldFile =, file, option, q) { |src|
puts "changed data: #{} #{src.handle.path}" if src.suspended?
# to cancel
# show last state and New State
def showChanges
file ="/path/to/config.plist", File::RDONLY).read
warn @oldFile
puts file
puts "_________________________________"
@oldFile = file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment