Currently Being ModeratedFeb 24, 2013 2:45 PM (in response to trwarren239)
So, after playing around a bit with the bookmark data stuff I did mange to come up with code that actually does what I was looking for, and have outlined it below in case it would be of value to anyone else.
First, to expand a little on the specific problem I am trying to solve (which I started a discussion on a year or so ago):
I have an iMac which is connected to network only via ethernet cable; wireless is disabled. The problem is that in OS X 10.8 when the computer comes out of a sleep state (either forced or idle) it takes roughly 15 seconds (on average) for the network connection to become active (sometimes 0, sometimes longer). This is a problem because the OS attempts to re-connect to previously mounted NAS volume right away and since there is no network connection, the mount is lost. This appears to be a bug in the OS as, for example, if I try to use the browser before the network connection is back, the browser will cache the request and re-issue it again when the network is available; the process for remounting network volumes doesn't do this. Also, I did not have this problem in earlier versions of OS 10.x.
The simple approach to handling this situation was to write a unix script which gets invoked each time the computer "wakes" up and performs the following logic:
(1) test to see if the network is active
(2) if not, repeat test (1) each second for some maximum number of seconds (and then exit if network doesn't become active)
(3) network is active, check to see if NAS volume is mounted
(4) if not mounted, issue commands to mount (mkdir, mount_afp)
This script works fine, but I wanted to accomplish same thing uisng cocoa app. Steps 1,2,3 were fairly easy to do but (4) wasn't due to deprecation mentioned in original post. The following experimental code was created to accomplish step 4:
(a) when NAS volume is properly mounted, obtain the bookmark data for the URL corresponding to the volume's NSURLVolumeURLForRemountingKey URL property and cache this data (I cached it into an NSData preference object for my applications Preference data, but you could also create an actual bookmark object). Use the NSURL bookmarkDataWithOptions instance method on that URL to get the bookmark data. Make sure to use includingResourceValuesForKeys form (which can have a nil value). For options, I used only the NSURLBookmarkCreationMinimalBookmark one.
(b) when you need to remount the volume, create a "new" URL using the URLByResolvingBookmakrData class method using the cached NSData object as the source of the bookmark data. This operation remounts the volume - also, at least for my app, the userid and password are not prompted for but seem to be available from the bookmark data (or keychain), which for me is convenient.
That's pretty much it.