How to get bookmarks data for non-existing files

  • This works fine (usually):
      BOOL isStale;
      NSError *outError;
      NSURL *url = [ NSURL URLByResolvingBookmarkData: bookmarksData
            options:      options
            relativeToURL:    nil
            bookmarkDataIsStale:  &isStale
            error:      &outError
          ];
    But when the referenced file does NOT exist, url will be nil and NSError just tells me: "File does not exist".
    But I would like to know what the (now non-existing) filename has been.

    How?

    Kind regards,

    Gerriet.
  • On Feb 7, 2012, at 22:58 , Gerriet M. Denkmann wrote:

    > This works fine (usually):
    > BOOL isStale;
    > NSError *outError;
    > NSURL *url =    [ NSURL URLByResolvingBookmarkData: bookmarksData
    > options:                     options
    > relativeToURL:                 nil
    > bookmarkDataIsStale:         &isStale
    > error:                         &outError
    > ];
    > But when the referenced file does NOT exist, url will be nil and NSError just tells me: "File does not exist".
    > But I would like to know what the (now non-existing) filename has been.
    >
    > How?

    Did you try +[NSURL resourceValuesForKeys:fromBookmarkData:]?
  • On 8 Feb 2012, at 14:30, Quincey Morris wrote:

    > On Feb 7, 2012, at 22:58 , Gerriet M. Denkmann wrote:
    >
    >> This works fine (usually):
    >> BOOL isStale;
    >> NSError *outError;
    >> NSURL *url =    [ NSURL URLByResolvingBookmarkData: bookmarksData
    >> options:                     options
    >> relativeToURL:                 nil
    >> bookmarkDataIsStale:         &isStale
    >> error:                         &outError
    >> ];
    >> But when the referenced file does NOT exist, url will be nil and NSError just tells me: "File does not exist".
    >> But I would like to know what the (now non-existing) filename has been.
    >>
    >> How?
    >
    > Did you try +[NSURL resourceValuesForKeys:fromBookmarkData:]?

    I had not. Right now I am trying it. But what keys to use? So far I got NSURLNameKey but there is more to get.
    Is there a list of usable keys somewhere?

    Gerriet.
  • On 8 Feb 2012, at 1:42 AM, Gerriet M. Denkmann wrote:

    >
    > On 8 Feb 2012, at 14:30, Quincey Morris wrote:
    >
    >> On Feb 7, 2012, at 22:58 , Gerriet M. Denkmann wrote:
    >>
    ...
    >>> But when the referenced file does NOT exist, url will be nil and NSError just tells me: "File does not exist".
    >>> But I would like to know what the (now non-existing) filename has been.
    >>>
    >>> How?
    >>
    >> Did you try +[NSURL resourceValuesForKeys:fromBookmarkData:]?
    >
    > I had not. Right now I am trying it. But what keys to use? So far I got NSURLNameKey but there is more to get.
    > Is there a list of usable keys somewhere?

    Have you searched for NSURLNameKey in NSURL.h? There are a number of string declarations after it, 25 for 10.6+, 9 for 10.7, and the documentation for resourceValuesForKeys:fromBookmarkData: says they apply.

    — F
  • On 8 Feb 2012, at 21:37, Fritz Anderson wrote:

    > On 8 Feb 2012, at 1:42 AM, Gerriet M. Denkmann wrote:
    >
    >>
    >> On 8 Feb 2012, at 14:30, Quincey Morris wrote:
    >>
    >>> On Feb 7, 2012, at 22:58 , Gerriet M. Denkmann wrote:
    >>>
    > ...
    >>>> But when the referenced file does NOT exist, url will be nil and NSError just tells me: "File does not exist".
    >>>> But I would like to know what the (now non-existing) filename has been.
    >>>>
    >>>> How?
    >>>
    >>> Did you try +[NSURL resourceValuesForKeys:fromBookmarkData:]?
    >>
    >> I had not. Right now I am trying it. But what keys to use? So far I got NSURLNameKey but there is more to get.
    >> Is there a list of usable keys somewhere?
    >
    > Have you searched for NSURLNameKey in NSURL.h? There are a number of string declarations after it, 25 for 10.6+, 9 for 10.7, and the documentation for resourceValuesForKeys:fromBookmarkData: says they apply.

    Thanks for this hint.

    The only keys which seem to work for an non-existing file seem to be:
    NSURLNameKey
    NSURLIsDirectoryKey
    NSURLIsRegularFileKey
    NSURLIsSymbolicLinkKey
    NSURLIsVolumeKey
    (I did try many, though not all).

    There is more info in the bookmarkData: like full path (this would be much more useful than just the NSURLNameKey), NSFileSystemFileNumber (probably not very useful in this case) and others.

    Kind regards,

    Gerriet.
  • On Feb 8, 2012, at 18:20 , Gerriet M. Denkmann wrote:

    > The only keys which seem to work for an non-existing file seem to be:
    > NSURLNameKey
    > NSURLIsDirectoryKey
    > NSURLIsRegularFileKey
    > NSURLIsSymbolicLinkKey
    > NSURLIsVolumeKey
    > (I did try many, though not all).
    >
    > There is more info in the bookmarkData: like full path (this would be much more useful than just the NSURLNameKey), NSFileSystemFileNumber (probably not very useful in this case) and others.

    I happened to notice this today:

    -[NSURL bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:]

    which suggests to me that the availability of keys depends on how the bookmark was created. If these are bookmarks you've created for yourself, then presumably you can add the information you will want if the target file is missing.
  • On 9 Feb 2012, at 10:33, Quincey Morris wrote:

    > On Feb 8, 2012, at 18:20 , Gerriet M. Denkmann wrote:
    >
    >> The only keys which seem to work for an non-existing file seem to be:
    >> NSURLNameKey
    >> NSURLIsDirectoryKey
    >> NSURLIsRegularFileKey
    >> NSURLIsSymbolicLinkKey
    >> NSURLIsVolumeKey
    >> (I did try many, though not all).
    >>
    >> There is more info in the bookmarkData: like full path (this would be much more useful than just the NSURLNameKey), NSFileSystemFileNumber (probably not very useful in this case) and others.
    >
    > I happened to notice this today:
    >
    > -[NSURL bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:]
    >
    > which suggests to me that the availability of keys depends on how the bookmark was created. If these are bookmarks you've created for yourself, then presumably you can add the information you will want if the target file is missing.

    No, these bookmarks are not created by me. They come from ~/Library/Preferences/com.apple.TextEdit.LSSharedFileList.plist.

    Here is the content of a typical bookmark (zero bytes replaced by @):

    Version    → 0x10010000
    Path Array  → /Volumes/เม่น/Users/gerriet/Source/Stuff 10.6.2/ไทย Dict Wv/Agenda.rtf
    Nodes Array → 497483, 2, 27, 2064, 55998, 2995129, 3624409, 7153541
    0x1010      → @@@@@@@@@@@@@@@@@@@@@@
    0x2000      → 61440, 0, 1, 0, 0, 0, 0, 0, 0
    0x2002      → /Volumes/เม่น
    0x2010      → เม่น
    0x2011      → 506E1F67-24E9-336E-89FC-8F6904D2FE79
    0x2012      → 51539607552
    0x2013      → 751533532737
    0x2020      → @@@@@ï?@@@@@@@@@@@@
    0xf080      → 3063f07b476c97a843db5b50742185c6499849c7;00000000;00000000;00000020;com.apple.app-sandbox.read-write;000000000e000004;00000000006d2785;@

    Any ideas what these keys might mean?

    Kind regards,

    Gerriet.
  • On Feb 9, 2012, at 7:06 AM, Gerriet M. Denkmann wrote:

    >
    > On 9 Feb 2012, at 10:33, Quincey Morris wrote:
    >
    >> On Feb 8, 2012, at 18:20 , Gerriet M. Denkmann wrote:
    >>
    >>> The only keys which seem to work for an non-existing file seem to be:
    >>> NSURLNameKey
    >>> NSURLIsDirectoryKey
    >>> NSURLIsRegularFileKey
    >>> NSURLIsSymbolicLinkKey
    >>> NSURLIsVolumeKey
    >>> (I did try many, though not all).
    >>>
    >>> There is more info in the bookmarkData: like full path (this would be much more useful than just the NSURLNameKey), NSFileSystemFileNumber (probably not very useful in this case) and others.
    >>
    >> I happened to notice this today:
    >>
    >> -[NSURL bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error:]
    >>
    >> which suggests to me that the availability of keys depends on how the bookmark was created. If these are bookmarks you've created for yourself, then presumably you can add the information you will want if the target file is missing.
    >
    > No, these bookmarks are not created by me. They come from ~/Library/Preferences/com.apple.TextEdit.LSSharedFileList.plist.
    >
    > Here is the content of a typical bookmark (zero bytes replaced by @):
    >
    > Version    → 0x10010000
    > Path Array  → /Volumes/เม่น/Users/gerriet/Source/Stuff 10.6.2/ไทย Dict Wv/Agenda.rtf
    > Nodes Array → 497483, 2, 27, 2064, 55998, 2995129, 3624409, 7153541
    > 0x1010      → @@@@@@@@@@@@@@@@@@@@@@
    > 0x2000      → 61440, 0, 1, 0, 0, 0, 0, 0, 0
    > 0x2002      → /Volumes/เม่น
    > 0x2010      → เม่น
    > 0x2011      → 506E1F67-24E9-336E-89FC-8F6904D2FE79
    > 0x2012      → 51539607552
    > 0x2013      → 751533532737
    > 0x2020      → @@@@@ï?@@@@@@@@@@@@
    > 0xf080      → 3063f07b476c97a843db5b50742185c6499849c7;00000000;00000000;00000020;com.apple.app-sandbox.read-write;000000000e000004;00000000006d2785;@
    >
    > Any ideas what these keys might mean?
    >
    >
    > Kind regards,
    >
    > Gerriet.
    >
    >
    The plist you are talking about is TextEdit's Open Recent menu list.
    It is just xml.
    Open the plist file (or a copy) in Xcode and see how it is structured.
    Then take a look at the source code for TextEdit.
    It might be somewhat revealing to look up LSSharedFileList.h

    From
    https://developer.apple.com/library/mac/#releasenotes/Carbon/RN-LaunchServi
    ces/_index.html


    The Shared File List API is new to Launch Services in Mac OS X Leopard. This API provides access to several kinds of system-global and per-user persistent lists of file system objects, such as recent documents and applications, favorites, and login items. For details, see the new interface file LSSharedFileList.h.
previous month february 2012 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29        
Go to today