• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Unexpectedly not getting dispatch_source events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unexpectedly not getting dispatch_source events


  • Subject: Unexpectedly not getting dispatch_source events
  • From: Rich Siegel <email@hidden>
  • Date: Tue, 24 May 2016 12:21:31 -0400

Good morning,

There are a lot of moving parts here, but I'll try to sketch this out clearly. :-)

My application has code which creates a DISPATCH_SOURCE_TYPE_VNODE to watch for changes in the backing file of an open document. When the source fires, I look at the flags and proceed based on what they indicate. A NOTE_WRITE means it's time to reload the document contents from disk, a NOTE_ATTRIB means that the modification date or some other metadata might have changed, NOTE_RENAME or NOTE_DELETE for moves, renames, and deletes, and so forth. This code is all tested and working as it should.

Next: it's possible for the user to attach AppleScript scripts to certain actions in the application; for example, a "documentDidSave" script to be called when saving has completed.

User scripts can do anything they want (within the confines of AppleScript execution), and a frequent use case is for users to write a documentDidSave script that runs the document through some transformation. So, for example, a documentDidSave script might run "astyle" to reformat source code.

Here's an extremely simple example of a -documentDidSave script, which adds "Hello World" to the end of the document that was just saved:

    on documentDidSave(doc)
        set d to (the file of doc) as text
        set f to POSIX path of file d
        set cmd to "echo \"Hello world
\" | cat >> " & quoted form of f
        do shell script cmd
    end documentDidSave

What I'm finding is that when this script runs *in my process* as the result of saving a document, I almost never get a NOTE_WRITE event, and sometimes I get a NOTE_ATTRIB that doesn't arrive until a couple of seconds after the script has run. (I have checked, and the file is being changed on disk as expected.)

On the other hand, if I run the script manually from the script editor, or even if I run the "echo" command in a Terminal window, the application *does* receive a NOTE_WRITE immediately.

I'm having a lot of trouble figuring out why file system event notifications would be lost (or not sent) in this situation; it seems oddly specific. I would expect to always get called when the file is changed, or never, but not sometimes-depending-on-who-ran-the-script.

I'd be grateful for any insight.

Thanks,

R.
--
Rich Siegel                                 Bare Bones Software, Inc.
<email@hidden>                      <http://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Filesystem-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Unexpectedly not getting dispatch_source events
      • From: Mark Day <email@hidden>
  • Prev by Date: Re: CFURLWriteBookmarkDataToFile fails with Alias records
  • Next by Date: Re: Unexpectedly not getting dispatch_source events
  • Previous by thread: Re: CFURLWriteBookmarkDataToFile fails with Alias records
  • Next by thread: Re: Unexpectedly not getting dispatch_source events
  • Index(es):
    • Date
    • Thread