Programmatically create aliases to unmounted servers?

  • All,

    I'm looking for a way to construct an alias file (a bookmark file) with a specific but unmounted file server location.  That is, I want to put an icon on user's desktops that says "Network Space" and have it resolve to afp://ser.ver.add.ress/mount/username.

    I can create an NSURL with the encoded path correctly, and I've tried to construct a bookmark file using NSURL's -bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error: and + writeBookmarkData:toURL:options:error:.  When I use a "smb" or "afp" URL I get a file that, when double clicked, opens in TextEdit with the contents of the bookmark file (that is, the URL).  I'm pretty sure my code is correct because if I change the URL to a local file I get a working bookmark file.  It also works if I construct the URL to a local path when the server is mounted (/Volumes/Server) - unmounting and opening the bookmark will re-mount the server.

    I've stared at the NSURL and File Manager references and it seems like there's no way to go from a text server reference to a bookmark file.  Is there a way to make an alias without mounting the server first?

    Thanks,

    --Jim
  • What you might want to do is create an AppleScript that is maybe run-only and is on the desktop.
    Way less pain.

    On Jan 24, 2012, at 4:24 PM, Zajkowski, James wrote:

    > All,
    >
    > I'm looking for a way to construct an alias file (a bookmark file) with a specific but unmounted file server location.  That is, I want to put an icon on user's desktops that says "Network Space" and have it resolve to afp://ser.ver.add.ress/mount/username.
    >
    > I can create an NSURL with the encoded path correctly, and I've tried to construct a bookmark file using NSURL's -bookmarkDataWithOptions:includingResourceValuesForKeys:relativeToURL:error: and + writeBookmarkData:toURL:options:error:.  When I use a "smb" or "afp" URL I get a file that, when double clicked, opens in TextEdit with the contents of the bookmark file (that is, the URL).  I'm pretty sure my code is correct because if I change the URL to a local file I get a working bookmark file.  It also works if I construct the URL to a local path when the server is mounted (/Volumes/Server) - unmounting and opening the bookmark will re-mount the server.
    >
    > I've stared at the NSURL and File Manager references and it seems like there's no way to go from a text server reference to a bookmark file.  Is there a way to make an alias without mounting the server first?
    >
    > Thanks,
    >
    > --Jim
    >
  • On Jan 24, 2012, at 4:24 PM, Zajkowski, James wrote:

    > I'm looking for a way to construct an alias file (a bookmark file) with a specific but unmounted file server location.  That is, I want to put an icon on user's desktops that says "Network Space" and have it resolve to afp://ser.ver.add.ress/mount/username.

    If I drag the above URL out of Mail and to the Finder, the Finder creates a .afploc file (like it would create a .webloc if I drag a web URL).  That .afploc file has a very straightforward format.  It's just a plist dictionary with a single key, "URL", with a string value which is the URL.

    You could create one of those.  Would that be sufficient?

    Regards,
    Ken
  • On Jan 24, 2012, at 10:50 PM, Ken Thomases wrote:

    > On Jan 24, 2012, at 4:24 PM, Zajkowski, James wrote:
    >
    >> I'm looking for a way to construct an alias file (a bookmark file) with a specific but unmounted file server location.  That is, I want to put an icon on user's desktops that says "Network Space" and have it resolve to afp://ser.ver.add.ress/mount/username.
    >
    > If I drag the above URL out of Mail and to the Finder, the Finder creates a .afploc file (like it would create a .webloc if I drag a web URL).  That .afploc file has a very straightforward format.  It's just a plist dictionary with a single key, "URL", with a string value which is the URL.
    >
    > You could create one of those.  Would that be sufficient?

    Well that does work, and it may have to be the interim solution.  The advantage of a true alias is that file dialogs will mount the server when the alias is clicked on, but they don't won't see the afploc files as a navigable thing.

    --Jim
previous month january 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
30 31          
Go to today