MBS Xojo Developer Conference and Training
Join us from 3rd to 6th May 2017 in Berlin, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

MacAliasMBS class

class, Alias, MBS Mac Plugin (Alias), class MacAliasMBS,
Mac: Yes, Win: No, Linux: No, Console & Web: Yes, Feedback.

Function: Gives access to Aliases on Mac.
// Store the reference to a FolderItem in a Binary File

Dim alias as MacAliasMBS
dim t,f as FolderItem
Dim bf as BinaryStream, s as String
bf = t.CreateBinaryFile("") // open your binary file here
f = SpecialFolder.Desktop // the FolderItem you want to save
alias = new MacAliasMBS
if alias.Create(nil, f) = 0 then
s = alias.GetRecord
bf.WriteLong LenB(s) // this saves the length of the record
bf.Write s // this saves the record itself

// Retrieve the reference to a FolderItem from a Binary File

dim l as Integer

bf = t.OpenAsBinaryFile(false) // open your binary file here
alias = new MacAliasMBS
l = bf.ReadLong
alias.SetRecord bf.Read(l)
f = alias.Resolve(nil, alias.attemptMount)
if alias.needsUpdate then
if alias.Update(nil, f) = 1 then
// ... you might want to save the updated alias in your file here
// f now describes the FolderItem again.
// It may not be existing any more, however, so here's a check for that:
if not f.exists then
msgBox "oops! the file is not available any more. Select a new one, please"
//... let the user locate the file
This Plugin implements a new Class for handling Mac OS Alias Records.

AliasRecords are like FolderItems, but can be made persistent: You can convert a FolderItem into a AliasRecord and store that AliasRecord in a file (like your Preferences file). Later you can retrieve that information again and convert it back into a FolderItem.

AliasRecords also appear inside Alias Files, that are usually created by the Finder. The enclosed sample application (Alias Mgr Plugin Demo.π) shows how to create and resolve such Alias Files.

Additional Background Information
The purpose of the class is to store paths to files and/or folders between runs of a RB application.
To store a path to a file/folder in an RB app, currently your only option is to get the abolute path as a string, and store that string in a file, usually your preferences file.
However, there is problem with using this technique: If, between runs of your app, the user changes the path of the file by moving it, or by renaming the file or any of its parent folders (including the volume name), your app will fail to locate the file next time
it is looking for it.
Fortunately, at least in Mac OS, there is a solution to this, which helps you to track your files in such a case. This is done by using Alias Records: they are the basic data structure that is also used in Alias Files as created and used in the Finder.
This class attempts to give the flexibility of Alias Records to your RB apps.

The meaning of the Relative path
When no relative path is specified, then the file is only located by its folder hierarchy down to the root of the volume. However, if a relative path is given, then the file is optionally located relative to that point.
So, if you locate files relatively to some folder, like the folder your application is in, you should specify your app's folder as the relative path so that the target is even found easily when the user moved the whole folder including your app and its related files. This is even more important when using this Alias class under Windows than under Mac OS (if files are moved in Mac OS, they often still can be found even without the help of the original folder hierarchy, while this is not possible under Windows 9x).

For Mac OS X 10.6 or newer, please also check CFBookmarkMBS module.

This class has no sub classes.

Some examples which use this class:

The items on this page are in the following plugins: MBS Mac Plugin.

MAAttachedWindowMBS   -   MacFileOperationMBS

MBS Realbasic Plugins