blob: 3a0f6ec04992ad69de62901c8b084347b64e8602 [file] [log] [blame]
Fred Drakec817e271998-08-10 18:40:22 +00001\section{\module{macfs} ---
2 FSSpec, the Alias Manager, \program{finder} aliases,
3 and the Standard File package.}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00004\declaremodule{builtin}{macfs}
5
6\modulesynopsis{Support for FSSpec, the Alias Manager, \program{finder} aliases,
7and the Standard File package.}
8
Jack Jansene4be9be1995-02-28 15:46:09 +00009
Guido van Rossum86751151995-02-28 17:14:32 +000010
Fred Drakecce10901998-03-17 06:33:25 +000011This module provides access to Macintosh FSSpec handling, the Alias
Fred Drake41788db1998-04-04 06:23:02 +000012Manager, \program{finder} aliases and the Standard File package.
13\index{Macintosh Alias Manager}
14\index{Alias Manager, Macintosh}
15\index{Standard File}
Jack Jansene4be9be1995-02-28 15:46:09 +000016
17Whenever a function or method expects a \var{file} argument, this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000018argument can be one of three things:\ (1) a full or partial Macintosh
Fred Drake41788db1998-04-04 06:23:02 +000019pathname, (2) an \pytype{FSSpec} object or (3) a 3-tuple \code{(\var{wdRefNum},
20\var{parID}, \var{name})} as described in \emph{Inside
21Macintosh:\ Files}\@. A description of aliases and the Standard File
22package can also be found there.
Jack Jansene4be9be1995-02-28 15:46:09 +000023
24\begin{funcdesc}{FSSpec}{file}
Fred Drake41788db1998-04-04 06:23:02 +000025Create an \pytype{FSSpec} object for the specified file.
Jack Jansene4be9be1995-02-28 15:46:09 +000026\end{funcdesc}
27
28\begin{funcdesc}{RawFSSpec}{data}
Fred Drake41788db1998-04-04 06:23:02 +000029Create an \pytype{FSSpec} object given the raw data for the \C{}
30structure for the \pytype{FSSpec} as a string. This is mainly useful
31if you have obtained an \pytype{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000032\end{funcdesc}
33
34\begin{funcdesc}{RawAlias}{data}
Fred Drake41788db1998-04-04 06:23:02 +000035Create an \pytype{Alias} object given the raw data for the \C{}
36structure for the alias as a string. This is mainly useful if you
37have obtained an \pytype{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000038\end{funcdesc}
39
Jack Jansene164bd81995-08-10 11:53:14 +000040\begin{funcdesc}{FInfo}{}
Fred Drake41788db1998-04-04 06:23:02 +000041Create a zero-filled \pytype{FInfo} object.
Jack Jansene164bd81995-08-10 11:53:14 +000042\end{funcdesc}
43
Jack Jansene4be9be1995-02-28 15:46:09 +000044\begin{funcdesc}{ResolveAliasFile}{file}
Fred Drake41788db1998-04-04 06:23:02 +000045Resolve an alias file. Returns a 3-tuple \code{(\var{fsspec},
46\var{isfolder}, \var{aliased})} where \var{fsspec} is the resulting
47\pytype{FSSpec} object, \var{isfolder} is true if \var{fsspec} points
48to a folder and \var{aliased} is true if the file was an alias in the
49first place (otherwise the \pytype{FSSpec} object for the file itself
50is returned).
Jack Jansene4be9be1995-02-28 15:46:09 +000051\end{funcdesc}
52
Fred Drakecce10901998-03-17 06:33:25 +000053\begin{funcdesc}{StandardGetFile}{\optional{type, ...}}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000054Present the user with a standard ``open input file''
Fred Drake41788db1998-04-04 06:23:02 +000055dialog. Optionally, you can pass up to four 4-character file types to limit
56the files the user can choose from. The function returns an \pytype{FSSpec}
Jack Jansene4be9be1995-02-28 15:46:09 +000057object and a flag indicating that the user completed the dialog
58without cancelling.
59\end{funcdesc}
60
Fred Drakecce10901998-03-17 06:33:25 +000061\begin{funcdesc}{PromptGetFile}{prompt\optional{, type, ...}}
Fred Drake41788db1998-04-04 06:23:02 +000062Similar to \function{StandardGetFile()} but allows you to specify a
63prompt.
Jack Jansen0e133741995-08-14 13:39:16 +000064\end{funcdesc}
65
Fred Drakecce10901998-03-17 06:33:25 +000066\begin{funcdesc}{StandardPutFile}{prompt, \optional{default}}
Jack Jansene4be9be1995-02-28 15:46:09 +000067Present the user with a standard ``open output file''
68dialog. \var{prompt} is the prompt string, and the optional
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000069\var{default} argument initializes the output file name. The function
Fred Drake41788db1998-04-04 06:23:02 +000070returns an \pytype{FSSpec} object and a flag indicating that the user
71completed the dialog without cancelling.
Jack Jansene4be9be1995-02-28 15:46:09 +000072\end{funcdesc}
73
Jack Jansen0e133741995-08-14 13:39:16 +000074\begin{funcdesc}{GetDirectory}{\optional{prompt}}
Jack Jansene4be9be1995-02-28 15:46:09 +000075Present the user with a non-standard ``select a directory''
Jack Jansen0e133741995-08-14 13:39:16 +000076dialog. \var{prompt} is the prompt string, and the optional.
Fred Drake41788db1998-04-04 06:23:02 +000077Return an \pytype{FSSpec} object and a success-indicator.
Jack Jansene4be9be1995-02-28 15:46:09 +000078\end{funcdesc}
79
Guido van Rossum910a6711996-07-30 18:22:31 +000080\begin{funcdesc}{SetFolder}{\optional{fsspec}}
81Set the folder that is initially presented to the user when one of
Fred Drake41788db1998-04-04 06:23:02 +000082the file selection dialogs is presented. \var{fsspec} should point to
Guido van Rossum910a6711996-07-30 18:22:31 +000083a file in the folder, not the folder itself (the file need not exist,
84though). If no argument is passed the folder will be set to the
Fred Drake41788db1998-04-04 06:23:02 +000085current directory, i.e. what \function{os.getcwd()} returns.
Guido van Rossum910a6711996-07-30 18:22:31 +000086
87Note that starting with system 7.5 the user can change Standard File
88behaviour with the ``general controls'' controlpanel, thereby making
89this call inoperative.
90\end{funcdesc}
91
Fred Drakecce10901998-03-17 06:33:25 +000092\begin{funcdesc}{FindFolder}{where, which, create}
Jack Jansene164bd81995-08-10 11:53:14 +000093Locates one of the ``special'' folders that MacOS knows about, such as
Fred Drake41788db1998-04-04 06:23:02 +000094the trash or the Preferences folder. \var{where} is the disk to
95search, \var{which} is the 4-character string specifying which folder to
Jack Jansenda53c521995-10-10 14:43:20 +000096locate. Setting \var{create} causes the folder to be created if it
Fred Drake41788db1998-04-04 06:23:02 +000097does not exist. Returns a \code{(\var{vrefnum}, \var{dirid})} tuple.
Fred Drake29996071997-08-22 13:45:13 +000098\end{funcdesc}
Jack Jansenda53c521995-10-10 14:43:20 +000099
Guido van Rossume229d861997-08-18 15:14:26 +0000100\begin{funcdesc}{NewAliasMinimalFromFullPath}{pathname}
Fred Drake41788db1998-04-04 06:23:02 +0000101Return a minimal \pytype{alias} object that points to the given file, which
Guido van Rossume229d861997-08-18 15:14:26 +0000102must be specified as a full pathname. This is the only way to create an
Fred Drake41788db1998-04-04 06:23:02 +0000103\pytype{Alias} pointing to a non-existing file.
Guido van Rossume229d861997-08-18 15:14:26 +0000104
Jack Jansenda53c521995-10-10 14:43:20 +0000105The constants for \var{where} and \var{which} can be obtained from the
106standard module \var{MACFS}.
Jack Jansene164bd81995-08-10 11:53:14 +0000107\end{funcdesc}
108
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000109\begin{funcdesc}{FindApplication}{creator}
110Locate the application with 4-char creator code \var{creator}. The
Fred Drake41788db1998-04-04 06:23:02 +0000111function returns an \pytype{FSSpec} object pointing to the application.
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000112\end{funcdesc}
113
Jack Jansene4be9be1995-02-28 15:46:09 +0000114\subsection{FSSpec objects}
Fred Drake41788db1998-04-04 06:23:02 +0000115\label{fsspec-objects}
Jack Jansene4be9be1995-02-28 15:46:09 +0000116
Fred Drake41788db1998-04-04 06:23:02 +0000117\begin{memberdesc}[FSSpec]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000118The raw data from the FSSpec object, suitable for passing
119to other applications, for instance.
Fred Drake41788db1998-04-04 06:23:02 +0000120\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000121
Fred Drake41788db1998-04-04 06:23:02 +0000122\begin{methoddesc}[FSSpec]{as_pathname}{}
123Return the full pathname of the file described by the \pytype{FSSpec}
124object.
125\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000126
Fred Drake41788db1998-04-04 06:23:02 +0000127\begin{methoddesc}[FSSpec]{as_tuple}{}
128Return the \code{(\var{wdRefNum}, \var{parID}, \var{name})} tuple of
129the file described by the \pytype{FSSpec} object.
130\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000131
Fred Drake41788db1998-04-04 06:23:02 +0000132\begin{methoddesc}[FSSpec]{NewAlias}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000133Create an Alias object pointing to the file described by this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000134FSSpec. If the optional \var{file} parameter is present the alias
Jack Jansene4be9be1995-02-28 15:46:09 +0000135will be relative to that file, otherwise it will be absolute.
Fred Drake41788db1998-04-04 06:23:02 +0000136\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000137
Fred Drake41788db1998-04-04 06:23:02 +0000138\begin{methoddesc}[FSSpec]{NewAliasMinimal}{}
Jack Jansene4be9be1995-02-28 15:46:09 +0000139Create a minimal alias pointing to this file.
Fred Drake41788db1998-04-04 06:23:02 +0000140\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000141
Fred Drake41788db1998-04-04 06:23:02 +0000142\begin{methoddesc}[FSSpec]{GetCreatorType}{}
143Return the 4-character creator and type of the file.
144\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000145
Fred Drake41788db1998-04-04 06:23:02 +0000146\begin{methoddesc}[FSSpec]{SetCreatorType}{creator, type}
147Set the 4-character creator and type of the file.
148\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000149
Fred Drake41788db1998-04-04 06:23:02 +0000150\begin{methoddesc}[FSSpec]{GetFInfo}{}
151Return a \pytype{FInfo} object describing the finder info for the file.
152\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000153
Fred Drake41788db1998-04-04 06:23:02 +0000154\begin{methoddesc}[FSSpec]{SetFInfo}{finfo}
155Set the finder info for the file to the values given as \var{finfo}
156(an \pytype{FInfo} object).
157\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000158
Fred Drake41788db1998-04-04 06:23:02 +0000159\begin{methoddesc}[FSSpec]{GetDates}{}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000160Return a tuple with three floating point values representing the
161creation date, modification date and backup date of the file.
Fred Drake41788db1998-04-04 06:23:02 +0000162\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000163
Fred Drake41788db1998-04-04 06:23:02 +0000164\begin{methoddesc}[FSSpec]{SetDates}{crdate, moddate, backupdate}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000165Set the creation, modification and backup date of the file. The values
166are in the standard floating point format used for times throughout
167Python.
Fred Drake41788db1998-04-04 06:23:02 +0000168\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000169
Jack Jansene4be9be1995-02-28 15:46:09 +0000170
Fred Drake41788db1998-04-04 06:23:02 +0000171\subsection{Alias Objects}
172\label{alias-objects}
173
174\begin{memberdesc}[Alias]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000175The raw data for the Alias record, suitable for storing in a resource
176or transmitting to other programs.
Fred Drake41788db1998-04-04 06:23:02 +0000177\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000178
Fred Drake41788db1998-04-04 06:23:02 +0000179\begin{methoddesc}[Alias]{Resolve}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000180Resolve the alias. If the alias was created as a relative alias you
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000181should pass the file relative to which it is. Return the FSSpec for
Fred Drake41788db1998-04-04 06:23:02 +0000182the file pointed to and a flag indicating whether the \pytype{Alias} object
Guido van Rossume229d861997-08-18 15:14:26 +0000183itself was modified during the search process. If the file does
184not exist but the path leading up to it does exist a valid fsspec
185is returned.
Fred Drake41788db1998-04-04 06:23:02 +0000186\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000187
Fred Drake41788db1998-04-04 06:23:02 +0000188\begin{methoddesc}[Alias]{GetInfo}{num}
189An interface to the \C{} routine \cfunction{GetAliasInfo()}.
190\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000191
Fred Drake41788db1998-04-04 06:23:02 +0000192\begin{methoddesc}[Alias]{Update}{file, \optional{file2}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000193Update the alias to point to the \var{file} given. If \var{file2} is
194present a relative alias will be created.
Fred Drake41788db1998-04-04 06:23:02 +0000195\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000196
Fred Drake41788db1998-04-04 06:23:02 +0000197Note that it is currently not possible to directly manipulate a
198resource as an \pytype{Alias} object. Hence, after calling
199\method{Update()} or after \method{Resolve()} indicates that the alias
200has changed the Python program is responsible for getting the
Fred Drakedf0e3fc1998-04-07 20:04:27 +0000201\member{data} value from the \pytype{Alias} object and modifying the
202resource.
Jack Jansene4be9be1995-02-28 15:46:09 +0000203
204
Fred Drake41788db1998-04-04 06:23:02 +0000205\subsection{FInfo Objects}
206\label{finfo-objects}
Jack Jansene164bd81995-08-10 11:53:14 +0000207
Fred Drake41788db1998-04-04 06:23:02 +0000208See \emph{Inside Macintosh: Files} for a complete description of what
209the various fields mean.
Jack Jansene164bd81995-08-10 11:53:14 +0000210
Fred Drake41788db1998-04-04 06:23:02 +0000211\begin{memberdesc}[FInfo]{Creator}
212The 4-character creator code of the file.
213\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000214
Fred Drake41788db1998-04-04 06:23:02 +0000215\begin{memberdesc}[FInfo]{Type}
216The 4-character type code of the file.
217\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000218
Fred Drake41788db1998-04-04 06:23:02 +0000219\begin{memberdesc}[FInfo]{Flags}
Jack Jansenda53c521995-10-10 14:43:20 +0000220The finder flags for the file as 16-bit integer. The bit values in
Fred Drake41788db1998-04-04 06:23:02 +0000221\var{Flags} are defined in standard module \module{MACFS}.
222\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000223
Fred Drake41788db1998-04-04 06:23:02 +0000224\begin{memberdesc}[FInfo]{Location}
Jack Jansene164bd81995-08-10 11:53:14 +0000225A Point giving the position of the file's icon in its folder.
Fred Drake41788db1998-04-04 06:23:02 +0000226\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000227
Fred Drake41788db1998-04-04 06:23:02 +0000228\begin{memberdesc}[FInfo]{Fldr}
Jack Jansene164bd81995-08-10 11:53:14 +0000229The folder the file is in (as an integer).
Fred Drake41788db1998-04-04 06:23:02 +0000230\end{memberdesc}