blob: 4b2f8fea2a467d2e873e868ba7cdb2494be4b8e8 [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Built-in Module \sectcode{macfs}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-macfs}
Jack Jansene4be9be1995-02-28 15:46:09 +00003\bimodindex{macfs}
4
Guido van Rossum86751151995-02-28 17:14:32 +00005\renewcommand{\indexsubitem}{(in module macfs)}
6
Jack Jansene4be9be1995-02-28 15:46:09 +00007This module provides access to macintosh FSSpec handling, the Alias
8Manager, finder aliases and the Standard File package.
9
10Whenever a function or method expects a \var{file} argument, this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000011argument can be one of three things:\ (1) a full or partial Macintosh
Jack Jansene4be9be1995-02-28 15:46:09 +000012pathname, (2) an FSSpec object or (3) a 3-tuple \code{(wdRefNum,
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000013parID, name)} as described in Inside Mac VI\@. A description of aliases
Jack Jansene4be9be1995-02-28 15:46:09 +000014and the standard file package can also be found there.
15
16\begin{funcdesc}{FSSpec}{file}
17Create an FSSpec object for the specified file.
18\end{funcdesc}
19
20\begin{funcdesc}{RawFSSpec}{data}
21Create an FSSpec object given the raw data for the C structure for the
Guido van Rossum470be141995-03-17 16:07:09 +000022FSSpec as a string. This is mainly useful if you have obtained an
23FSSpec structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000024\end{funcdesc}
25
26\begin{funcdesc}{RawAlias}{data}
Guido van Rossum470be141995-03-17 16:07:09 +000027Create an Alias object given the raw data for the C structure for the
28alias as a string. This is mainly useful if you have obtained an
29FSSpec structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000030\end{funcdesc}
31
Jack Jansene164bd81995-08-10 11:53:14 +000032\begin{funcdesc}{FInfo}{}
33Create a zero-filled FInfo object.
34\end{funcdesc}
35
Jack Jansene4be9be1995-02-28 15:46:09 +000036\begin{funcdesc}{ResolveAliasFile}{file}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000037Resolve an alias file. Returns a 3-tuple \code{(\var{fsspec}, \var{isfolder},
38\var{aliased})} where \var{fsspec} is the resulting FSSpec object,
Jack Jansene4be9be1995-02-28 15:46:09 +000039\var{isfolder} is true if \var{fsspec} points to a folder and
40\var{aliased} is true if the file was an alias in the first place
41(otherwise the FSSpec object for the file itself is returned).
42\end{funcdesc}
43
44\begin{funcdesc}{StandardGetFile}{\optional{type\, ...}}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000045Present the user with a standard ``open input file''
Jack Jansene4be9be1995-02-28 15:46:09 +000046dialog. Optionally, you can pass up to four 4-char file types to limit
47the files the user can choose from. The function returns an FSSpec
48object and a flag indicating that the user completed the dialog
49without cancelling.
50\end{funcdesc}
51
Jack Jansen0e133741995-08-14 13:39:16 +000052\begin{funcdesc}{PromptGetFile}{prompt\optional{\, type\, ...}}
53Similar to \var{StandardGetFile} but allows you to specify a prompt.
54\end{funcdesc}
55
Jack Jansene4be9be1995-02-28 15:46:09 +000056\begin{funcdesc}{StandardPutFile}{prompt\, \optional{default}}
57Present the user with a standard ``open output file''
58dialog. \var{prompt} is the prompt string, and the optional
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000059\var{default} argument initializes the output file name. The function
Jack Jansene4be9be1995-02-28 15:46:09 +000060returns an FSSpec object and a flag indicating that the user completed
61the dialog without cancelling.
62\end{funcdesc}
63
Jack Jansen0e133741995-08-14 13:39:16 +000064\begin{funcdesc}{GetDirectory}{\optional{prompt}}
Jack Jansene4be9be1995-02-28 15:46:09 +000065Present the user with a non-standard ``select a directory''
Jack Jansen0e133741995-08-14 13:39:16 +000066dialog. \var{prompt} is the prompt string, and the optional.
67Return an FSSpec object and a success-indicator.
Jack Jansene4be9be1995-02-28 15:46:09 +000068\end{funcdesc}
69
Guido van Rossum910a6711996-07-30 18:22:31 +000070\begin{funcdesc}{SetFolder}{\optional{fsspec}}
71Set the folder that is initially presented to the user when one of
72the file selection dialogs is presented. \var{Fsspec} should point to
73a file in the folder, not the folder itself (the file need not exist,
74though). If no argument is passed the folder will be set to the
75current directory, i.e. what \code{os.getcwd()} returns.
76
77Note that starting with system 7.5 the user can change Standard File
78behaviour with the ``general controls'' controlpanel, thereby making
79this call inoperative.
80\end{funcdesc}
81
Jack Jansene164bd81995-08-10 11:53:14 +000082\begin{funcdesc}{FindFolder}{where\, which\, create}
83Locates one of the ``special'' folders that MacOS knows about, such as
Jack Jansenda53c521995-10-10 14:43:20 +000084the trash or the Preferences folder. \var{Where} is the disk to
85search, \var{which} is the 4-char string specifying which folder to
86locate. Setting \var{create} causes the folder to be created if it
87does not exist. Returns a \code{(vrefnum, dirid)} tuple.
Fred Drake29996071997-08-22 13:45:13 +000088\end{funcdesc}
Jack Jansenda53c521995-10-10 14:43:20 +000089
Guido van Rossume229d861997-08-18 15:14:26 +000090\begin{funcdesc}{NewAliasMinimalFromFullPath}{pathname}
91Return a minimal alias record object that points to the given file, which
92must be specified as a full pathname. This is the only way to create an
93alias record pointing to a non-existing file.
94
Jack Jansenda53c521995-10-10 14:43:20 +000095The constants for \var{where} and \var{which} can be obtained from the
96standard module \var{MACFS}.
Jack Jansene164bd81995-08-10 11:53:14 +000097\end{funcdesc}
98
Guido van Rossum7e42cab1996-10-15 14:37:31 +000099\begin{funcdesc}{FindApplication}{creator}
100Locate the application with 4-char creator code \var{creator}. The
101function returns an FSSpec object pointing to the application.
102\end{funcdesc}
103
Jack Jansene4be9be1995-02-28 15:46:09 +0000104\subsection{FSSpec objects}
105
Guido van Rossum470be141995-03-17 16:07:09 +0000106\renewcommand{\indexsubitem}{(FSSpec object attribute)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000107\begin{datadesc}{data}
108The raw data from the FSSpec object, suitable for passing
109to other applications, for instance.
110\end{datadesc}
111
Guido van Rossum470be141995-03-17 16:07:09 +0000112\renewcommand{\indexsubitem}{(FSSpec object method)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000113\begin{funcdesc}{as_pathname}{}
114Return the full pathname of the file described by the FSSpec object.
115\end{funcdesc}
116
117\begin{funcdesc}{as_tuple}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000118Return the \code{(\var{wdRefNum}, \var{parID}, \var{name})} tuple of the file described
Jack Jansene4be9be1995-02-28 15:46:09 +0000119by the FSSpec object.
120\end{funcdesc}
121
122\begin{funcdesc}{NewAlias}{\optional{file}}
123Create an Alias object pointing to the file described by this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000124FSSpec. If the optional \var{file} parameter is present the alias
Jack Jansene4be9be1995-02-28 15:46:09 +0000125will be relative to that file, otherwise it will be absolute.
126\end{funcdesc}
127
128\begin{funcdesc}{NewAliasMinimal}{}
129Create a minimal alias pointing to this file.
130\end{funcdesc}
131
132\begin{funcdesc}{GetCreatorType}{}
133Return the 4-char creator and type of the file.
134\end{funcdesc}
135
136\begin{funcdesc}{SetCreatorType}{creator\, type}
137Set the 4-char creator and type of the file.
138\end{funcdesc}
139
Jack Jansene164bd81995-08-10 11:53:14 +0000140\begin{funcdesc}{GetFInfo}{}
141Return a FInfo object describing the finder info for the file.
142\end{funcdesc}
143
144\begin{funcdesc}{SetFInfo}{finfo}
145Set the finder info for the file to the values specified in the
146\var{finfo} object.
147\end{funcdesc}
148
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000149\begin{funcdesc}{GetDates}{}
150Return a tuple with three floating point values representing the
151creation date, modification date and backup date of the file.
152\end{funcdesc}
153
154\begin{funcdesc}{SetDates}{crdate\, moddate\, backupdate}
155Set the creation, modification and backup date of the file. The values
156are in the standard floating point format used for times throughout
157Python.
158\end{funcdesc}
159
Jack Jansene4be9be1995-02-28 15:46:09 +0000160\subsection{alias objects}
161
Guido van Rossum470be141995-03-17 16:07:09 +0000162\renewcommand{\indexsubitem}{(alias object attribute)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000163\begin{datadesc}{data}
164The raw data for the Alias record, suitable for storing in a resource
165or transmitting to other programs.
166\end{datadesc}
167
Guido van Rossum470be141995-03-17 16:07:09 +0000168\renewcommand{\indexsubitem}{(alias object method)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000169\begin{funcdesc}{Resolve}{\optional{file}}
170Resolve the alias. If the alias was created as a relative alias you
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000171should pass the file relative to which it is. Return the FSSpec for
Jack Jansene4be9be1995-02-28 15:46:09 +0000172the file pointed to and a flag indicating whether the alias object
Guido van Rossume229d861997-08-18 15:14:26 +0000173itself was modified during the search process. If the file does
174not exist but the path leading up to it does exist a valid fsspec
175is returned.
Jack Jansene4be9be1995-02-28 15:46:09 +0000176\end{funcdesc}
177
178\begin{funcdesc}{GetInfo}{num}
179An interface to the C routine \code{GetAliasInfo()}.
180\end{funcdesc}
181
182\begin{funcdesc}{Update}{file\, \optional{file2}}
183Update the alias to point to the \var{file} given. If \var{file2} is
184present a relative alias will be created.
185\end{funcdesc}
186
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000187Note that it is currently not possible to directly manipulate a resource
Jack Jansene4be9be1995-02-28 15:46:09 +0000188as an alias object. Hence, after calling \var{Update} or after
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000189\var{Resolve} indicates that the alias has changed the Python program
Jack Jansene4be9be1995-02-28 15:46:09 +0000190is responsible for getting the \var{data} from the alias object and
191modifying the resource.
192
193
Jack Jansene164bd81995-08-10 11:53:14 +0000194\subsection{FInfo objects}
195
196See Inside Mac for a complete description of what the various fields
197mean.
198
199\renewcommand{\indexsubitem}{(FInfo object attribute)}
200\begin{datadesc}{Creator}
201The 4-char creator code of the file.
202\end{datadesc}
203
204\begin{datadesc}{Type}
205The 4-char type code of the file.
206\end{datadesc}
207
208\begin{datadesc}{Flags}
Jack Jansenda53c521995-10-10 14:43:20 +0000209The finder flags for the file as 16-bit integer. The bit values in
210\var{Flags} are defined in standard module \var{MACFS}.
Jack Jansene164bd81995-08-10 11:53:14 +0000211\end{datadesc}
212
213\begin{datadesc}{Location}
214A Point giving the position of the file's icon in its folder.
215\end{datadesc}
216
217\begin{datadesc}{Fldr}
218The folder the file is in (as an integer).
219\end{datadesc}