I'm trying to enter a file path into a few .pref files, but instead of a String, the field wants some sort of Hexadecimal sequence. How can I convert my path into this Hex format?
Mac OS 10.6.7
Here is an example of a file location:
<00000000 009e0003 00010000 c94bbb14 0000482b 00000000 000d3ad2 000dfc12 0000c950 e4db0000 00000920 fffe0000 00000000 0000ffff ffff0001 0008000d 3ad2000c 9ce1000e 000c0005 0069006e 0062006f 0078000f 001a000c 004d0061 00630069 006e0074 006f0073 00680020 00480044 00120015 55736572 732f7263 68617265 7474652f 696e626f 78000013 00012f00 00150002 0010ffff 0000>
It's alias
'alis'
data, which has been the standard way to refer to files in a persistent manner in Mac OS for the last 20 years or more. ;-) TheAliasHandle
et. al are found inAliases.h
, which is in theCarbonCore.framework
of theCoreServices
umbrella framework.Note that it is Property List Editor (or Xcode) that's showing you a hexadecimal representation of
NSData
. The data tells us that you haven't changed the name of your hard drive (it appears to still be "Macintosh HD") and that the path of the alias was to/Users/rcharette/inbox
The "newfangled" name for this is bookmark data, which was introduced in 10.6.
There are a couple of high-level wrappers around aliases, Nathan Day's
NDAlias
, I believe.Otherwise, the following is mine, a category on
NSString
modeled after the new bookmark APIs available inNSURL
(which require 10.6). (This code should work on 10.3+):MDBookmarks.h:
MDBookmarks.m:
—
Otherwise, if you can require 10.6, then check out the newer APIs in
NSURL
.Paths in preference files are sometimes base64 encoded. You can use openssl to de/encode the values:
Decode:
echo <encoded-path> | openssl enc -d -base64
Encode:
echo <path> | openssl enc -e -base64