blob: 36610e8d3a21e021736e67b533029216612a05de [file] [log] [blame]
Fred Drakec817e271998-08-10 18:40:22 +00001\section{\module{macfs} ---
Fred Drakef6863c11999-03-02 16:37:17 +00002 Various file system services}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00003
Fred Drakef6863c11999-03-02 16:37:17 +00004\declaremodule{builtin}{macfs}
5 \platform{Mac}
Fred Drake72554e41998-11-25 20:07:35 +00006\modulesynopsis{Support for FSSpec, the Alias Manager,
7 \program{finder} aliases, and the Standard File package.}
Fred Drakefe7f3bc1998-07-23 17:55:31 +00008
Jack Jansene4be9be1995-02-28 15:46:09 +00009
Fred Drakecce10901998-03-17 06:33:25 +000010This module provides access to Macintosh FSSpec handling, the Alias
Fred Drake41788db1998-04-04 06:23:02 +000011Manager, \program{finder} aliases and the Standard File package.
12\index{Macintosh Alias Manager}
13\index{Alias Manager, Macintosh}
14\index{Standard File}
Jack Jansene4be9be1995-02-28 15:46:09 +000015
16Whenever a function or method expects a \var{file} argument, this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000017argument can be one of three things:\ (1) a full or partial Macintosh
Fred Drakeeecdc7f2000-10-14 04:45:22 +000018pathname, (2) an \pytype{FSSpec} object or (3) a 3-tuple
19\code{(\var{wdRefNum}, \var{parID}, \var{name})} as described in
20\citetitle{Inside Macintosh:\ Files}. A description of aliases and the
21Standard File package can also be found there.
22
Fred Drake0aa811c2001-10-20 04:24:09 +000023\note{A module, \refmodule{macfsn}, is auto-imported to replace
24StandardFile calls in \module{macfs} with NavServices calls.}
Jack Jansene4be9be1995-02-28 15:46:09 +000025
26\begin{funcdesc}{FSSpec}{file}
Fred Drake41788db1998-04-04 06:23:02 +000027Create an \pytype{FSSpec} object for the specified file.
Jack Jansene4be9be1995-02-28 15:46:09 +000028\end{funcdesc}
29
30\begin{funcdesc}{RawFSSpec}{data}
Fred Drake41788db1998-04-04 06:23:02 +000031Create an \pytype{FSSpec} object given the raw data for the \C{}
32structure for the \pytype{FSSpec} as a string. This is mainly useful
33if you have obtained an \pytype{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000034\end{funcdesc}
35
36\begin{funcdesc}{RawAlias}{data}
Fred Drake41788db1998-04-04 06:23:02 +000037Create an \pytype{Alias} object given the raw data for the \C{}
38structure for the alias as a string. This is mainly useful if you
39have obtained an \pytype{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000040\end{funcdesc}
41
Jack Jansene164bd81995-08-10 11:53:14 +000042\begin{funcdesc}{FInfo}{}
Fred Drake41788db1998-04-04 06:23:02 +000043Create a zero-filled \pytype{FInfo} object.
Jack Jansene164bd81995-08-10 11:53:14 +000044\end{funcdesc}
45
Jack Jansene4be9be1995-02-28 15:46:09 +000046\begin{funcdesc}{ResolveAliasFile}{file}
Fred Drake41788db1998-04-04 06:23:02 +000047Resolve an alias file. Returns a 3-tuple \code{(\var{fsspec},
48\var{isfolder}, \var{aliased})} where \var{fsspec} is the resulting
49\pytype{FSSpec} object, \var{isfolder} is true if \var{fsspec} points
50to a folder and \var{aliased} is true if the file was an alias in the
51first place (otherwise the \pytype{FSSpec} object for the file itself
52is returned).
Jack Jansene4be9be1995-02-28 15:46:09 +000053\end{funcdesc}
54
Fred Drake4c6d21a2000-09-22 15:46:35 +000055\begin{funcdesc}{StandardGetFile}{\optional{type, \moreargs}}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000056Present the user with a standard ``open input file''
Fred Drake41788db1998-04-04 06:23:02 +000057dialog. Optionally, you can pass up to four 4-character file types to limit
58the files the user can choose from. The function returns an \pytype{FSSpec}
Jack Jansene4be9be1995-02-28 15:46:09 +000059object and a flag indicating that the user completed the dialog
60without cancelling.
61\end{funcdesc}
62
Fred Drake4c6d21a2000-09-22 15:46:35 +000063\begin{funcdesc}{PromptGetFile}{prompt\optional{, type, \moreargs}}
Fred Drake41788db1998-04-04 06:23:02 +000064Similar to \function{StandardGetFile()} but allows you to specify a
Fred Drakeeecdc7f2000-10-14 04:45:22 +000065prompt which will be displayed at the top of the dialog.
Jack Jansen0e133741995-08-14 13:39:16 +000066\end{funcdesc}
67
Fred Drake4c6d21a2000-09-22 15:46:35 +000068\begin{funcdesc}{StandardPutFile}{prompt\optional{, default}}
Jack Jansene4be9be1995-02-28 15:46:09 +000069Present the user with a standard ``open output file''
70dialog. \var{prompt} is the prompt string, and the optional
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000071\var{default} argument initializes the output file name. The function
Fred Drake41788db1998-04-04 06:23:02 +000072returns an \pytype{FSSpec} object and a flag indicating that the user
73completed the dialog without cancelling.
Jack Jansene4be9be1995-02-28 15:46:09 +000074\end{funcdesc}
75
Jack Jansen0e133741995-08-14 13:39:16 +000076\begin{funcdesc}{GetDirectory}{\optional{prompt}}
Fred Drakeeecdc7f2000-10-14 04:45:22 +000077Present the user with a non-standard ``select a directory'' dialog. You
78have to first open the directory before clicking on the ``select current
79directory'' button. \var{prompt} is the prompt string which will be
80displayed at the top of the dialog. Return an \pytype{FSSpec} object and
81a success-indicator.
Jack Jansene4be9be1995-02-28 15:46:09 +000082\end{funcdesc}
83
Guido van Rossum910a6711996-07-30 18:22:31 +000084\begin{funcdesc}{SetFolder}{\optional{fsspec}}
85Set the folder that is initially presented to the user when one of
Fred Drake41788db1998-04-04 06:23:02 +000086the file selection dialogs is presented. \var{fsspec} should point to
Guido van Rossum910a6711996-07-30 18:22:31 +000087a file in the folder, not the folder itself (the file need not exist,
88though). If no argument is passed the folder will be set to the
Fred Drake41788db1998-04-04 06:23:02 +000089current directory, i.e. what \function{os.getcwd()} returns.
Guido van Rossum910a6711996-07-30 18:22:31 +000090
91Note that starting with system 7.5 the user can change Standard File
Fred Drakeeecdc7f2000-10-14 04:45:22 +000092behaviour with the ``general controls'' control panel, thereby making
Guido van Rossum910a6711996-07-30 18:22:31 +000093this call inoperative.
94\end{funcdesc}
95
Fred Drakecce10901998-03-17 06:33:25 +000096\begin{funcdesc}{FindFolder}{where, which, create}
Jack Jansene164bd81995-08-10 11:53:14 +000097Locates one of the ``special'' folders that MacOS knows about, such as
Fred Drake41788db1998-04-04 06:23:02 +000098the trash or the Preferences folder. \var{where} is the disk to
99search, \var{which} is the 4-character string specifying which folder to
Jack Jansenda53c521995-10-10 14:43:20 +0000100locate. Setting \var{create} causes the folder to be created if it
Fred Drake41788db1998-04-04 06:23:02 +0000101does not exist. Returns a \code{(\var{vrefnum}, \var{dirid})} tuple.
Fred Drake29996071997-08-22 13:45:13 +0000102\end{funcdesc}
Jack Jansenda53c521995-10-10 14:43:20 +0000103
Guido van Rossume229d861997-08-18 15:14:26 +0000104\begin{funcdesc}{NewAliasMinimalFromFullPath}{pathname}
Fred Drake41788db1998-04-04 06:23:02 +0000105Return a minimal \pytype{alias} object that points to the given file, which
Guido van Rossume229d861997-08-18 15:14:26 +0000106must be specified as a full pathname. This is the only way to create an
Fred Drake41788db1998-04-04 06:23:02 +0000107\pytype{Alias} pointing to a non-existing file.
Guido van Rossume229d861997-08-18 15:14:26 +0000108
Jack Jansenda53c521995-10-10 14:43:20 +0000109The constants for \var{where} and \var{which} can be obtained from the
110standard module \var{MACFS}.
Jack Jansene164bd81995-08-10 11:53:14 +0000111\end{funcdesc}
112
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000113\begin{funcdesc}{FindApplication}{creator}
Fred Drakeeecdc7f2000-10-14 04:45:22 +0000114Locate the application with 4-character creator code \var{creator}. The
Fred Drake41788db1998-04-04 06:23:02 +0000115function returns an \pytype{FSSpec} object pointing to the application.
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000116\end{funcdesc}
117
Fred Drakef6863c11999-03-02 16:37:17 +0000118
Fred Drakeefff11b2002-01-17 04:44:34 +0000119\subsection{FSSpec Objects \label{fsspec-objects}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000120
Fred Drake41788db1998-04-04 06:23:02 +0000121\begin{memberdesc}[FSSpec]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000122The raw data from the FSSpec object, suitable for passing
123to other applications, for instance.
Fred Drake41788db1998-04-04 06:23:02 +0000124\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000125
Fred Drake41788db1998-04-04 06:23:02 +0000126\begin{methoddesc}[FSSpec]{as_pathname}{}
127Return the full pathname of the file described by the \pytype{FSSpec}
128object.
129\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000130
Fred Drake41788db1998-04-04 06:23:02 +0000131\begin{methoddesc}[FSSpec]{as_tuple}{}
132Return the \code{(\var{wdRefNum}, \var{parID}, \var{name})} tuple of
133the file described by the \pytype{FSSpec} object.
134\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000135
Fred Drake41788db1998-04-04 06:23:02 +0000136\begin{methoddesc}[FSSpec]{NewAlias}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000137Create an Alias object pointing to the file described by this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000138FSSpec. If the optional \var{file} parameter is present the alias
Jack Jansene4be9be1995-02-28 15:46:09 +0000139will be relative to that file, otherwise it will be absolute.
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]{NewAliasMinimal}{}
Jack Jansene4be9be1995-02-28 15:46:09 +0000143Create a minimal alias pointing to this file.
Fred Drake41788db1998-04-04 06:23:02 +0000144\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000145
Fred Drake41788db1998-04-04 06:23:02 +0000146\begin{methoddesc}[FSSpec]{GetCreatorType}{}
147Return 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]{SetCreatorType}{creator, type}
151Set the 4-character creator and type of the file.
152\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000153
Fred Drake41788db1998-04-04 06:23:02 +0000154\begin{methoddesc}[FSSpec]{GetFInfo}{}
155Return a \pytype{FInfo} object describing the finder info for the file.
156\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000157
Fred Drake41788db1998-04-04 06:23:02 +0000158\begin{methoddesc}[FSSpec]{SetFInfo}{finfo}
159Set the finder info for the file to the values given as \var{finfo}
160(an \pytype{FInfo} object).
161\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000162
Fred Drake41788db1998-04-04 06:23:02 +0000163\begin{methoddesc}[FSSpec]{GetDates}{}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000164Return a tuple with three floating point values representing the
165creation date, modification date and backup date of the file.
Fred Drake41788db1998-04-04 06:23:02 +0000166\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000167
Fred Drake41788db1998-04-04 06:23:02 +0000168\begin{methoddesc}[FSSpec]{SetDates}{crdate, moddate, backupdate}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000169Set the creation, modification and backup date of the file. The values
170are in the standard floating point format used for times throughout
171Python.
Fred Drake41788db1998-04-04 06:23:02 +0000172\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000173
Jack Jansene4be9be1995-02-28 15:46:09 +0000174
Fred Drakef6863c11999-03-02 16:37:17 +0000175\subsection{Alias Objects \label{alias-objects}}
Fred Drake41788db1998-04-04 06:23:02 +0000176
177\begin{memberdesc}[Alias]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000178The raw data for the Alias record, suitable for storing in a resource
179or transmitting to other programs.
Fred Drake41788db1998-04-04 06:23:02 +0000180\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000181
Fred Drake41788db1998-04-04 06:23:02 +0000182\begin{methoddesc}[Alias]{Resolve}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000183Resolve the alias. If the alias was created as a relative alias you
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000184should pass the file relative to which it is. Return the FSSpec for
Fred Drake41788db1998-04-04 06:23:02 +0000185the file pointed to and a flag indicating whether the \pytype{Alias} object
Guido van Rossume229d861997-08-18 15:14:26 +0000186itself was modified during the search process. If the file does
187not exist but the path leading up to it does exist a valid fsspec
188is returned.
Fred Drake41788db1998-04-04 06:23:02 +0000189\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000190
Fred Drake41788db1998-04-04 06:23:02 +0000191\begin{methoddesc}[Alias]{GetInfo}{num}
192An interface to the \C{} routine \cfunction{GetAliasInfo()}.
193\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000194
Fred Drake4c6d21a2000-09-22 15:46:35 +0000195\begin{methoddesc}[Alias]{Update}{file\optional{, file2}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000196Update the alias to point to the \var{file} given. If \var{file2} is
197present a relative alias will be created.
Fred Drake41788db1998-04-04 06:23:02 +0000198\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000199
Fred Drake41788db1998-04-04 06:23:02 +0000200Note that it is currently not possible to directly manipulate a
201resource as an \pytype{Alias} object. Hence, after calling
202\method{Update()} or after \method{Resolve()} indicates that the alias
203has changed the Python program is responsible for getting the
Fred Drakedf0e3fc1998-04-07 20:04:27 +0000204\member{data} value from the \pytype{Alias} object and modifying the
205resource.
Jack Jansene4be9be1995-02-28 15:46:09 +0000206
207
Fred Drakef6863c11999-03-02 16:37:17 +0000208\subsection{FInfo Objects \label{finfo-objects}}
Jack Jansene164bd81995-08-10 11:53:14 +0000209
Fred Drakee15eb351999-11-10 16:13:25 +0000210See \citetitle{Inside Macintosh: Files} for a complete description of what
Fred Drake41788db1998-04-04 06:23:02 +0000211the various fields mean.
Jack Jansene164bd81995-08-10 11:53:14 +0000212
Fred Drake41788db1998-04-04 06:23:02 +0000213\begin{memberdesc}[FInfo]{Creator}
214The 4-character creator code of the file.
215\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000216
Fred Drake41788db1998-04-04 06:23:02 +0000217\begin{memberdesc}[FInfo]{Type}
218The 4-character type code of the file.
219\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000220
Fred Drake41788db1998-04-04 06:23:02 +0000221\begin{memberdesc}[FInfo]{Flags}
Jack Jansenda53c521995-10-10 14:43:20 +0000222The finder flags for the file as 16-bit integer. The bit values in
Fred Drake41788db1998-04-04 06:23:02 +0000223\var{Flags} are defined in standard module \module{MACFS}.
224\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000225
Fred Drake41788db1998-04-04 06:23:02 +0000226\begin{memberdesc}[FInfo]{Location}
Jack Jansene164bd81995-08-10 11:53:14 +0000227A Point giving the position of the file's icon in its folder.
Fred Drake41788db1998-04-04 06:23:02 +0000228\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000229
Fred Drake41788db1998-04-04 06:23:02 +0000230\begin{memberdesc}[FInfo]{Fldr}
Jack Jansene164bd81995-08-10 11:53:14 +0000231The folder the file is in (as an integer).
Fred Drake41788db1998-04-04 06:23:02 +0000232\end{memberdesc}