blob: 944ea1bc46f39ea00cbfddefbe8f19ad03b87e36 [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
Jack Jansen7aeba452003-02-12 09:58:33 +00004\declaremodule{standard}{macfs}
Fred Drakef6863c11999-03-02 16:37:17 +00005 \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 Jansen7aeba452003-02-12 09:58:33 +00009\deprecated{2.3}{The macfs module should be considered obsolete. For
10\class{FSSpec}, \class{FSRef} and \class{Alias} handling use the
Fred Drake6a002ca2003-09-05 14:01:15 +000011\module{Carbon.File} or \refmodule{Carbon.Folder} module. For file
Nicholas Bastincfa157d2004-06-06 01:17:52 +000012dialogs use the \refmodule{EasyDialogs} module. Also, this module is
13known to not work correctly with UFS partitions.}
Jack Jansene4be9be1995-02-28 15:46:09 +000014
Fred Drake6a002ca2003-09-05 14:01:15 +000015This module provides access to Macintosh \class{FSSpec} handling, the
16Alias Manager, \program{finder} aliases and the Standard File package.
Fred Drake41788db1998-04-04 06:23:02 +000017\index{Macintosh Alias Manager}
18\index{Alias Manager, Macintosh}
19\index{Standard File}
Jack Jansene4be9be1995-02-28 15:46:09 +000020
21Whenever a function or method expects a \var{file} argument, this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000022argument can be one of three things:\ (1) a full or partial Macintosh
Jack Jansen7aeba452003-02-12 09:58:33 +000023pathname, (2) an \class{FSSpec} object or (3) a 3-tuple
Fred Drakeeecdc7f2000-10-14 04:45:22 +000024\code{(\var{wdRefNum}, \var{parID}, \var{name})} as described in
Jack Jansen7aeba452003-02-12 09:58:33 +000025\citetitle{Inside Macintosh:\ Files}. An \class{FSSpec} can point to
Jack Jansend37f75b2002-08-06 22:15:23 +000026a non-existing file, as long as the folder containing the file exists.
27Under MacPython the same is true for a pathname, but not under unix-Pyton
28because of the way pathnames and FSRefs works. See Apple's documentation
29for details.
30
31A description of aliases and the
Fred Drakeeecdc7f2000-10-14 04:45:22 +000032Standard File package can also be found there.
33
Jack Jansene4be9be1995-02-28 15:46:09 +000034\begin{funcdesc}{FSSpec}{file}
Jack Jansen7aeba452003-02-12 09:58:33 +000035Create an \class{FSSpec} object for the specified file.
Jack Jansene4be9be1995-02-28 15:46:09 +000036\end{funcdesc}
37
38\begin{funcdesc}{RawFSSpec}{data}
Jack Jansen7aeba452003-02-12 09:58:33 +000039Create an \class{FSSpec} object given the raw data for the \C{}
40structure for the \class{FSSpec} as a string. This is mainly useful
41if you have obtained an \class{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000042\end{funcdesc}
43
44\begin{funcdesc}{RawAlias}{data}
Jack Jansen7aeba452003-02-12 09:58:33 +000045Create an \class{Alias} object given the raw data for the \C{}
Fred Drake41788db1998-04-04 06:23:02 +000046structure for the alias as a string. This is mainly useful if you
Jack Jansen7aeba452003-02-12 09:58:33 +000047have obtained an \class{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000048\end{funcdesc}
49
Jack Jansene164bd81995-08-10 11:53:14 +000050\begin{funcdesc}{FInfo}{}
Jack Jansen7aeba452003-02-12 09:58:33 +000051Create a zero-filled \class{FInfo} object.
Jack Jansene164bd81995-08-10 11:53:14 +000052\end{funcdesc}
53
Jack Jansene4be9be1995-02-28 15:46:09 +000054\begin{funcdesc}{ResolveAliasFile}{file}
Fred Drake41788db1998-04-04 06:23:02 +000055Resolve an alias file. Returns a 3-tuple \code{(\var{fsspec},
56\var{isfolder}, \var{aliased})} where \var{fsspec} is the resulting
Jack Jansen7aeba452003-02-12 09:58:33 +000057\class{FSSpec} object, \var{isfolder} is true if \var{fsspec} points
Fred Drake41788db1998-04-04 06:23:02 +000058to a folder and \var{aliased} is true if the file was an alias in the
Jack Jansen7aeba452003-02-12 09:58:33 +000059first place (otherwise the \class{FSSpec} object for the file itself
Fred Drake41788db1998-04-04 06:23:02 +000060is returned).
Jack Jansene4be9be1995-02-28 15:46:09 +000061\end{funcdesc}
62
Fred Drake4c6d21a2000-09-22 15:46:35 +000063\begin{funcdesc}{StandardGetFile}{\optional{type, \moreargs}}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000064Present the user with a standard ``open input file''
Fred Drake41788db1998-04-04 06:23:02 +000065dialog. Optionally, you can pass up to four 4-character file types to limit
Jack Jansen7aeba452003-02-12 09:58:33 +000066the files the user can choose from. The function returns an \class{FSSpec}
Jack Jansene4be9be1995-02-28 15:46:09 +000067object and a flag indicating that the user completed the dialog
68without cancelling.
69\end{funcdesc}
70
Fred Drake4c6d21a2000-09-22 15:46:35 +000071\begin{funcdesc}{PromptGetFile}{prompt\optional{, type, \moreargs}}
Fred Drake41788db1998-04-04 06:23:02 +000072Similar to \function{StandardGetFile()} but allows you to specify a
Fred Drakeeecdc7f2000-10-14 04:45:22 +000073prompt which will be displayed at the top of the dialog.
Jack Jansen0e133741995-08-14 13:39:16 +000074\end{funcdesc}
75
Fred Drake4c6d21a2000-09-22 15:46:35 +000076\begin{funcdesc}{StandardPutFile}{prompt\optional{, default}}
Jack Jansene4be9be1995-02-28 15:46:09 +000077Present the user with a standard ``open output file''
78dialog. \var{prompt} is the prompt string, and the optional
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000079\var{default} argument initializes the output file name. The function
Jack Jansen7aeba452003-02-12 09:58:33 +000080returns an \class{FSSpec} object and a flag indicating that the user
Fred Drake41788db1998-04-04 06:23:02 +000081completed the dialog without cancelling.
Jack Jansene4be9be1995-02-28 15:46:09 +000082\end{funcdesc}
83
Jack Jansen0e133741995-08-14 13:39:16 +000084\begin{funcdesc}{GetDirectory}{\optional{prompt}}
Fred Drakeeecdc7f2000-10-14 04:45:22 +000085Present the user with a non-standard ``select a directory'' dialog. You
86have to first open the directory before clicking on the ``select current
87directory'' button. \var{prompt} is the prompt string which will be
Jack Jansen7aeba452003-02-12 09:58:33 +000088displayed at the top of the dialog. Return an \class{FSSpec} object and
Fred Drakeeecdc7f2000-10-14 04:45:22 +000089a success-indicator.
Jack Jansene4be9be1995-02-28 15:46:09 +000090\end{funcdesc}
91
Guido van Rossum910a6711996-07-30 18:22:31 +000092\begin{funcdesc}{SetFolder}{\optional{fsspec}}
93Set the folder that is initially presented to the user when one of
Fred Drake41788db1998-04-04 06:23:02 +000094the file selection dialogs is presented. \var{fsspec} should point to
Guido van Rossum910a6711996-07-30 18:22:31 +000095a file in the folder, not the folder itself (the file need not exist,
96though). If no argument is passed the folder will be set to the
Fred Drake41788db1998-04-04 06:23:02 +000097current directory, i.e. what \function{os.getcwd()} returns.
Guido van Rossum910a6711996-07-30 18:22:31 +000098
Fred Drake6a002ca2003-09-05 14:01:15 +000099Note that starting with System 7.5 the user can change Standard File
Fred Drakeeecdc7f2000-10-14 04:45:22 +0000100behaviour with the ``general controls'' control panel, thereby making
Guido van Rossum910a6711996-07-30 18:22:31 +0000101this call inoperative.
102\end{funcdesc}
103
Fred Drakecce10901998-03-17 06:33:25 +0000104\begin{funcdesc}{FindFolder}{where, which, create}
Fred Drake6a002ca2003-09-05 14:01:15 +0000105Locates one of the ``special'' folders that Mac OS knows about, such as
Fred Drake41788db1998-04-04 06:23:02 +0000106the trash or the Preferences folder. \var{where} is the disk to
107search, \var{which} is the 4-character string specifying which folder to
Jack Jansenda53c521995-10-10 14:43:20 +0000108locate. Setting \var{create} causes the folder to be created if it
Fred Drake41788db1998-04-04 06:23:02 +0000109does not exist. Returns a \code{(\var{vrefnum}, \var{dirid})} tuple.
Jack Jansen7aeba452003-02-12 09:58:33 +0000110
111The constants for \var{where} and \var{which} can be obtained from the
112standard module \var{Carbon.Folders}.
Fred Drake29996071997-08-22 13:45:13 +0000113\end{funcdesc}
Jack Jansenda53c521995-10-10 14:43:20 +0000114
Guido van Rossume229d861997-08-18 15:14:26 +0000115\begin{funcdesc}{NewAliasMinimalFromFullPath}{pathname}
Jack Jansen7aeba452003-02-12 09:58:33 +0000116Return a minimal \class{alias} object that points to the given file, which
Guido van Rossume229d861997-08-18 15:14:26 +0000117must be specified as a full pathname. This is the only way to create an
Jack Jansen7aeba452003-02-12 09:58:33 +0000118\class{Alias} pointing to a non-existing file.
Guido van Rossume229d861997-08-18 15:14:26 +0000119
Jack Jansene164bd81995-08-10 11:53:14 +0000120\end{funcdesc}
121
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000122\begin{funcdesc}{FindApplication}{creator}
Fred Drakeeecdc7f2000-10-14 04:45:22 +0000123Locate the application with 4-character creator code \var{creator}. The
Jack Jansen7aeba452003-02-12 09:58:33 +0000124function returns an \class{FSSpec} object pointing to the application.
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000125\end{funcdesc}
126
Fred Drakef6863c11999-03-02 16:37:17 +0000127
Fred Drakeefff11b2002-01-17 04:44:34 +0000128\subsection{FSSpec Objects \label{fsspec-objects}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000129
Fred Drake41788db1998-04-04 06:23:02 +0000130\begin{memberdesc}[FSSpec]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000131The raw data from the FSSpec object, suitable for passing
132to other applications, for instance.
Fred Drake41788db1998-04-04 06:23:02 +0000133\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000134
Fred Drake41788db1998-04-04 06:23:02 +0000135\begin{methoddesc}[FSSpec]{as_pathname}{}
Jack Jansen7aeba452003-02-12 09:58:33 +0000136Return the full pathname of the file described by the \class{FSSpec}
Fred Drake41788db1998-04-04 06:23:02 +0000137object.
138\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000139
Fred Drake41788db1998-04-04 06:23:02 +0000140\begin{methoddesc}[FSSpec]{as_tuple}{}
141Return the \code{(\var{wdRefNum}, \var{parID}, \var{name})} tuple of
Jack Jansen7aeba452003-02-12 09:58:33 +0000142the file described by the \class{FSSpec} object.
Fred Drake41788db1998-04-04 06:23:02 +0000143\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000144
Fred Drake41788db1998-04-04 06:23:02 +0000145\begin{methoddesc}[FSSpec]{NewAlias}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000146Create an Alias object pointing to the file described by this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000147FSSpec. If the optional \var{file} parameter is present the alias
Jack Jansene4be9be1995-02-28 15:46:09 +0000148will be relative to that file, otherwise it will be absolute.
Fred Drake41788db1998-04-04 06:23:02 +0000149\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000150
Fred Drake41788db1998-04-04 06:23:02 +0000151\begin{methoddesc}[FSSpec]{NewAliasMinimal}{}
Jack Jansene4be9be1995-02-28 15:46:09 +0000152Create a minimal alias pointing to this file.
Fred Drake41788db1998-04-04 06:23:02 +0000153\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000154
Fred Drake41788db1998-04-04 06:23:02 +0000155\begin{methoddesc}[FSSpec]{GetCreatorType}{}
156Return the 4-character creator and type of the file.
157\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000158
Fred Drake41788db1998-04-04 06:23:02 +0000159\begin{methoddesc}[FSSpec]{SetCreatorType}{creator, type}
160Set the 4-character creator and type of the file.
161\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000162
Fred Drake41788db1998-04-04 06:23:02 +0000163\begin{methoddesc}[FSSpec]{GetFInfo}{}
Jack Jansen7aeba452003-02-12 09:58:33 +0000164Return a \class{FInfo} object describing the finder info for the file.
Fred Drake41788db1998-04-04 06:23:02 +0000165\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000166
Fred Drake41788db1998-04-04 06:23:02 +0000167\begin{methoddesc}[FSSpec]{SetFInfo}{finfo}
168Set the finder info for the file to the values given as \var{finfo}
Jack Jansen7aeba452003-02-12 09:58:33 +0000169(an \class{FInfo} object).
Fred Drake41788db1998-04-04 06:23:02 +0000170\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000171
Fred Drake41788db1998-04-04 06:23:02 +0000172\begin{methoddesc}[FSSpec]{GetDates}{}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000173Return a tuple with three floating point values representing the
174creation date, modification date and backup date of the file.
Fred Drake41788db1998-04-04 06:23:02 +0000175\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000176
Fred Drake41788db1998-04-04 06:23:02 +0000177\begin{methoddesc}[FSSpec]{SetDates}{crdate, moddate, backupdate}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000178Set the creation, modification and backup date of the file. The values
179are in the standard floating point format used for times throughout
180Python.
Fred Drake41788db1998-04-04 06:23:02 +0000181\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000182
Jack Jansene4be9be1995-02-28 15:46:09 +0000183
Fred Drakef6863c11999-03-02 16:37:17 +0000184\subsection{Alias Objects \label{alias-objects}}
Fred Drake41788db1998-04-04 06:23:02 +0000185
186\begin{memberdesc}[Alias]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000187The raw data for the Alias record, suitable for storing in a resource
188or transmitting to other programs.
Fred Drake41788db1998-04-04 06:23:02 +0000189\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000190
Fred Drake41788db1998-04-04 06:23:02 +0000191\begin{methoddesc}[Alias]{Resolve}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000192Resolve the alias. If the alias was created as a relative alias you
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000193should pass the file relative to which it is. Return the FSSpec for
Jack Jansen7aeba452003-02-12 09:58:33 +0000194the file pointed to and a flag indicating whether the \class{Alias} object
Guido van Rossume229d861997-08-18 15:14:26 +0000195itself was modified during the search process. If the file does
196not exist but the path leading up to it does exist a valid fsspec
197is returned.
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 +0000200\begin{methoddesc}[Alias]{GetInfo}{num}
201An interface to the \C{} routine \cfunction{GetAliasInfo()}.
202\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000203
Fred Drake4c6d21a2000-09-22 15:46:35 +0000204\begin{methoddesc}[Alias]{Update}{file\optional{, file2}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000205Update the alias to point to the \var{file} given. If \var{file2} is
206present a relative alias will be created.
Fred Drake41788db1998-04-04 06:23:02 +0000207\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000208
Fred Drake41788db1998-04-04 06:23:02 +0000209Note that it is currently not possible to directly manipulate a
Jack Jansen7aeba452003-02-12 09:58:33 +0000210resource as an \class{Alias} object. Hence, after calling
Fred Drake41788db1998-04-04 06:23:02 +0000211\method{Update()} or after \method{Resolve()} indicates that the alias
212has changed the Python program is responsible for getting the
Jack Jansen7aeba452003-02-12 09:58:33 +0000213\member{data} value from the \class{Alias} object and modifying the
Fred Drakedf0e3fc1998-04-07 20:04:27 +0000214resource.
Jack Jansene4be9be1995-02-28 15:46:09 +0000215
216
Fred Drakef6863c11999-03-02 16:37:17 +0000217\subsection{FInfo Objects \label{finfo-objects}}
Jack Jansene164bd81995-08-10 11:53:14 +0000218
Fred Drakee15eb351999-11-10 16:13:25 +0000219See \citetitle{Inside Macintosh: Files} for a complete description of what
Fred Drake41788db1998-04-04 06:23:02 +0000220the various fields mean.
Jack Jansene164bd81995-08-10 11:53:14 +0000221
Fred Drake41788db1998-04-04 06:23:02 +0000222\begin{memberdesc}[FInfo]{Creator}
223The 4-character creator code of the file.
224\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000225
Fred Drake41788db1998-04-04 06:23:02 +0000226\begin{memberdesc}[FInfo]{Type}
227The 4-character type code of the file.
228\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000229
Fred Drake41788db1998-04-04 06:23:02 +0000230\begin{memberdesc}[FInfo]{Flags}
Jack Jansenda53c521995-10-10 14:43:20 +0000231The finder flags for the file as 16-bit integer. The bit values in
Fred Drake41788db1998-04-04 06:23:02 +0000232\var{Flags} are defined in standard module \module{MACFS}.
233\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000234
Fred Drake41788db1998-04-04 06:23:02 +0000235\begin{memberdesc}[FInfo]{Location}
Jack Jansene164bd81995-08-10 11:53:14 +0000236A Point giving the position of the file's icon in its folder.
Fred Drake41788db1998-04-04 06:23:02 +0000237\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000238
Fred Drake41788db1998-04-04 06:23:02 +0000239\begin{memberdesc}[FInfo]{Fldr}
Jack Jansene164bd81995-08-10 11:53:14 +0000240The folder the file is in (as an integer).
Fred Drake41788db1998-04-04 06:23:02 +0000241\end{memberdesc}