blob: 0ce4ff12f2ea5bb16efda46978094fba8416bb93 [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.
88
Guido van Rossume229d861997-08-18 15:14:26 +000089\begin{funcdesc}{NewAliasMinimalFromFullPath}{pathname}
90Return a minimal alias record object that points to the given file, which
91must be specified as a full pathname. This is the only way to create an
92alias record pointing to a non-existing file.
93
Jack Jansenda53c521995-10-10 14:43:20 +000094The constants for \var{where} and \var{which} can be obtained from the
95standard module \var{MACFS}.
Jack Jansene164bd81995-08-10 11:53:14 +000096\end{funcdesc}
97
Guido van Rossum7e42cab1996-10-15 14:37:31 +000098\begin{funcdesc}{FindApplication}{creator}
99Locate the application with 4-char creator code \var{creator}. The
100function returns an FSSpec object pointing to the application.
101\end{funcdesc}
102
Jack Jansene4be9be1995-02-28 15:46:09 +0000103\subsection{FSSpec objects}
104
Guido van Rossum470be141995-03-17 16:07:09 +0000105\renewcommand{\indexsubitem}{(FSSpec object attribute)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000106\begin{datadesc}{data}
107The raw data from the FSSpec object, suitable for passing
108to other applications, for instance.
109\end{datadesc}
110
Guido van Rossum470be141995-03-17 16:07:09 +0000111\renewcommand{\indexsubitem}{(FSSpec object method)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000112\begin{funcdesc}{as_pathname}{}
113Return the full pathname of the file described by the FSSpec object.
114\end{funcdesc}
115
116\begin{funcdesc}{as_tuple}{}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000117Return the \code{(\var{wdRefNum}, \var{parID}, \var{name})} tuple of the file described
Jack Jansene4be9be1995-02-28 15:46:09 +0000118by the FSSpec object.
119\end{funcdesc}
120
121\begin{funcdesc}{NewAlias}{\optional{file}}
122Create an Alias object pointing to the file described by this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000123FSSpec. If the optional \var{file} parameter is present the alias
Jack Jansene4be9be1995-02-28 15:46:09 +0000124will be relative to that file, otherwise it will be absolute.
125\end{funcdesc}
126
127\begin{funcdesc}{NewAliasMinimal}{}
128Create a minimal alias pointing to this file.
129\end{funcdesc}
130
131\begin{funcdesc}{GetCreatorType}{}
132Return the 4-char creator and type of the file.
133\end{funcdesc}
134
135\begin{funcdesc}{SetCreatorType}{creator\, type}
136Set the 4-char creator and type of the file.
137\end{funcdesc}
138
Jack Jansene164bd81995-08-10 11:53:14 +0000139\begin{funcdesc}{GetFInfo}{}
140Return a FInfo object describing the finder info for the file.
141\end{funcdesc}
142
143\begin{funcdesc}{SetFInfo}{finfo}
144Set the finder info for the file to the values specified in the
145\var{finfo} object.
146\end{funcdesc}
147
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000148\begin{funcdesc}{GetDates}{}
149Return a tuple with three floating point values representing the
150creation date, modification date and backup date of the file.
151\end{funcdesc}
152
153\begin{funcdesc}{SetDates}{crdate\, moddate\, backupdate}
154Set the creation, modification and backup date of the file. The values
155are in the standard floating point format used for times throughout
156Python.
157\end{funcdesc}
158
Jack Jansene4be9be1995-02-28 15:46:09 +0000159\subsection{alias objects}
160
Guido van Rossum470be141995-03-17 16:07:09 +0000161\renewcommand{\indexsubitem}{(alias object attribute)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000162\begin{datadesc}{data}
163The raw data for the Alias record, suitable for storing in a resource
164or transmitting to other programs.
165\end{datadesc}
166
Guido van Rossum470be141995-03-17 16:07:09 +0000167\renewcommand{\indexsubitem}{(alias object method)}
Jack Jansene4be9be1995-02-28 15:46:09 +0000168\begin{funcdesc}{Resolve}{\optional{file}}
169Resolve the alias. If the alias was created as a relative alias you
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000170should pass the file relative to which it is. Return the FSSpec for
Jack Jansene4be9be1995-02-28 15:46:09 +0000171the file pointed to and a flag indicating whether the alias object
Guido van Rossume229d861997-08-18 15:14:26 +0000172itself was modified during the search process. If the file does
173not exist but the path leading up to it does exist a valid fsspec
174is returned.
Jack Jansene4be9be1995-02-28 15:46:09 +0000175\end{funcdesc}
176
177\begin{funcdesc}{GetInfo}{num}
178An interface to the C routine \code{GetAliasInfo()}.
179\end{funcdesc}
180
181\begin{funcdesc}{Update}{file\, \optional{file2}}
182Update the alias to point to the \var{file} given. If \var{file2} is
183present a relative alias will be created.
184\end{funcdesc}
185
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000186Note that it is currently not possible to directly manipulate a resource
Jack Jansene4be9be1995-02-28 15:46:09 +0000187as an alias object. Hence, after calling \var{Update} or after
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000188\var{Resolve} indicates that the alias has changed the Python program
Jack Jansene4be9be1995-02-28 15:46:09 +0000189is responsible for getting the \var{data} from the alias object and
190modifying the resource.
191
192
Jack Jansene164bd81995-08-10 11:53:14 +0000193\subsection{FInfo objects}
194
195See Inside Mac for a complete description of what the various fields
196mean.
197
198\renewcommand{\indexsubitem}{(FInfo object attribute)}
199\begin{datadesc}{Creator}
200The 4-char creator code of the file.
201\end{datadesc}
202
203\begin{datadesc}{Type}
204The 4-char type code of the file.
205\end{datadesc}
206
207\begin{datadesc}{Flags}
Jack Jansenda53c521995-10-10 14:43:20 +0000208The finder flags for the file as 16-bit integer. The bit values in
209\var{Flags} are defined in standard module \var{MACFS}.
Jack Jansene164bd81995-08-10 11:53:14 +0000210\end{datadesc}
211
212\begin{datadesc}{Location}
213A Point giving the position of the file's icon in its folder.
214\end{datadesc}
215
216\begin{datadesc}{Fldr}
217The folder the file is in (as an integer).
218\end{datadesc}