py-mactypes manual | 2. Alias class

#

## 2. The `Alias` class

The `Alias` class represents a persistent reference to a filesystem object. Aliases keep track of filesystem objects even if they're renamed or moved to another location on the same disk.

### Methods

    Alias -- A persistent reference to a filesystem object. Aliases keep
            track of filesystem objects as they're moved around the disk
            or renamed. Provides a variety of properties and constructors
            for converting to and from other Python types.

        Constructors:

            Alias(path) -- make Alias object from POSIX path

    	File.makewithhfspath(path) -- make Alias object from HFS path

            Alias.makewithurl(url) -- make Alias object from file URL

            Alias.makewithdesc(desc) -- make Alias object from an
                    AEDesc of typeAlias

        Properties:

            path : unicode -- POSIX path

    	hfspath : unicode -- HFS path

            url : string -- file URL

            file : mactypes.File

            alias : mactypes.Alias -- itself

            desc : aem.ae.AEDesc

### Examples

    from appscript import *
    from mactypes import *

    f = Alias('/Users/foo/some file')

    print f
    # mactypes.Alias("/Users/foo/some file")

    print f.path
    # /Users/foo/some file

    app('TextEdit').open(f)
    # opens document in TextEdit

    Alias('/some/non/existent/location')
    # ValueError: Can't make mactypes.Alias as file doesn't exist:
    #     '/some/non/existent/location'

### Notes

When creating an `Alias` instance, POSIX paths may be either relative or absolute and are automatically normalised using `os.path.abspath`. Paths to non-existent filesystem locations will result in a `ValueError` being raised.

Note that comparing an `Alias` object against a `File` object always returns false, even if both point to the same location.

Remember that aliases can change when the corresponding filesystem object is moved, so take care when using `Alias` objects in situations that involve comparing or hashing them (e.g. as `dict` keys).