mac_alias - Generate/parse Mac OS Alias records from Python¶
This document refers to version 1.1.0
What is this?¶
The Mac OS has a special data structure it calls an Alias, which allows programs that make use of it to locate the file to which it refers more reliably than they would be able to from e.g. a filename alone.
The format of this structure is not documented, so until recently you would have used Mac OS X APIs to construct and process Alias records. Sadly, Apple has deprecated the APIs in question in favour of its new “Bookmark” functionality; this is understandable, but it makes it tricky to construct an Alias record reliably in future.
This module contains code to parse and generate Alias records from a Pythonic equivalent data structure, and does not rely on the deprecated APIs.
Usage¶
To parse an Alias record given binary data:
from mac_alias import Alias
a = Alias.from_bytes(my_data)
To generate a binary Alias record:
a.to_bytes()
Finally, to build an Alias
for a file:
Alias.for_file('/path/to/file.ext')
It’s probably best to resist the temptation to mess with the Alias class too much otherwise.
Code Documentation¶
Contents:
mac_alias package¶
Classes¶
-
class
mac_alias.
Alias
(appinfo='x00x00x00x00', version=2, volume=None, target=None, extra=[])¶ -
appinfo
= None¶ Application specific information (four byte byte-string)
-
extra
= None¶ A list of extra (tag, value) pairs
-
target
= None¶ A
TargetInfo
object describing the target
-
version
= None¶ Version (we support only version 2)
-
volume
= None¶ A
VolumeInfo
object describing the target’s volume
-
The AFP server
The username
The AppleShare zone
-
class
mac_alias.
TargetInfo
(kind, filename, folder_cnid, cnid, creation_date, creator_code, type_code, levels_from=-1, levels_to=-1, folder_name=None, cnid_path=None, carbon_path=None, posix_path=None, user_home_prefix_len=None)¶ -
carbon_path
= None¶ The Carbon path of the target (optional)
-
cnid
= None¶ The CNID (Catalog Node ID) of the target
-
cnid_path
= None¶ The path from the volume root as a sequence of CNIDs. (optional)
-
creation_date
= None¶ The target’s creation date.
-
creator_code
= None¶ The target’s Mac creator code (a four-character binary string)
-
filename
= None¶ The filename of the target
-
folder_cnid
= None¶ The CNID (Catalog Node ID) of the target’s containing folder; CNIDs are similar to but different than traditional UNIX inode numbers
-
folder_name
= None¶ The (POSIX) name of the target’s containing folder. (optional)
-
kind
= None¶ Either ALIAS_KIND_FILE or ALIAS_KIND_FOLDER
-
levels_from
= None¶ The depth of the alias? Always seems to be -1 on OS X.
-
levels_to
= None¶ The depth of the target? Always seems to be -1 on OS X.
-
posix_path
= None¶ The POSIX path of the target relative to the volume root. Note that this may or may not have a leading ‘/’ character, but it is always relative to the containing volume. (optional)
-
type_code
= None¶ The target’s Mac type code (a four-character binary string)
-
user_home_prefix_len
= None¶ If the path points into a user’s home folder, the number of folders deep that we go before we get to that home folder. (optional)
-
Constants¶
-
mac_alias.
ALIAS_HFS_VOLUME_SIGNATURE
¶ The volume signature for HFS+.
-
mac_alias.
ALIAS_FIXED_DISK
¶ -
mac_alias.
ALIAS_NETWORK_DISK
¶ -
mac_alias.
ALIAS_400KB_FLOPPY_DISK
¶ -
mac_alias.
ALIAS_800KB_FLOPPY_DISK
¶ -
mac_alias.
ALIAS_1_44MB_FLOPPY_DISK
¶ -
mac_alias.
ALIAS_EJECTABLE_DISK
¶ Disk type constants.
-
mac_alias.
ALIAS_NO_CNID
¶ A constant used where no CNID is present.