blob: f6265ea589abf1c835423277d520597fe977f60c [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
12dialogs use the \refmodule{EasyDialogs} module.}
Jack Jansene4be9be1995-02-28 15:46:09 +000013
Fred Drake6a002ca2003-09-05 14:01:15 +000014This module provides access to Macintosh \class{FSSpec} handling, the
15Alias Manager, \program{finder} aliases and the Standard File package.
Fred Drake41788db1998-04-04 06:23:02 +000016\index{Macintosh Alias Manager}
17\index{Alias Manager, Macintosh}
18\index{Standard File}
Jack Jansene4be9be1995-02-28 15:46:09 +000019
20Whenever a function or method expects a \var{file} argument, this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000021argument can be one of three things:\ (1) a full or partial Macintosh
Jack Jansen7aeba452003-02-12 09:58:33 +000022pathname, (2) an \class{FSSpec} object or (3) a 3-tuple
Fred Drakeeecdc7f2000-10-14 04:45:22 +000023\code{(\var{wdRefNum}, \var{parID}, \var{name})} as described in
Jack Jansen7aeba452003-02-12 09:58:33 +000024\citetitle{Inside Macintosh:\ Files}. An \class{FSSpec} can point to
Jack Jansend37f75b2002-08-06 22:15:23 +000025a non-existing file, as long as the folder containing the file exists.
26Under MacPython the same is true for a pathname, but not under unix-Pyton
27because of the way pathnames and FSRefs works. See Apple's documentation
28for details.
29
30A description of aliases and the
Fred Drakeeecdc7f2000-10-14 04:45:22 +000031Standard File package can also be found there.
32
Jack Jansene4be9be1995-02-28 15:46:09 +000033\begin{funcdesc}{FSSpec}{file}
Jack Jansen7aeba452003-02-12 09:58:33 +000034Create an \class{FSSpec} object for the specified file.
Jack Jansene4be9be1995-02-28 15:46:09 +000035\end{funcdesc}
36
37\begin{funcdesc}{RawFSSpec}{data}
Jack Jansen7aeba452003-02-12 09:58:33 +000038Create an \class{FSSpec} object given the raw data for the \C{}
39structure for the \class{FSSpec} as a string. This is mainly useful
40if you have obtained an \class{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000041\end{funcdesc}
42
43\begin{funcdesc}{RawAlias}{data}
Jack Jansen7aeba452003-02-12 09:58:33 +000044Create an \class{Alias} object given the raw data for the \C{}
Fred Drake41788db1998-04-04 06:23:02 +000045structure for the alias as a string. This is mainly useful if you
Jack Jansen7aeba452003-02-12 09:58:33 +000046have obtained an \class{FSSpec} structure over a network.
Jack Jansene4be9be1995-02-28 15:46:09 +000047\end{funcdesc}
48
Jack Jansene164bd81995-08-10 11:53:14 +000049\begin{funcdesc}{FInfo}{}
Jack Jansen7aeba452003-02-12 09:58:33 +000050Create a zero-filled \class{FInfo} object.
Jack Jansene164bd81995-08-10 11:53:14 +000051\end{funcdesc}
52
Jack Jansene4be9be1995-02-28 15:46:09 +000053\begin{funcdesc}{ResolveAliasFile}{file}
Fred Drake41788db1998-04-04 06:23:02 +000054Resolve an alias file. Returns a 3-tuple \code{(\var{fsspec},
55\var{isfolder}, \var{aliased})} where \var{fsspec} is the resulting
Jack Jansen7aeba452003-02-12 09:58:33 +000056\class{FSSpec} object, \var{isfolder} is true if \var{fsspec} points
Fred Drake41788db1998-04-04 06:23:02 +000057to a folder and \var{aliased} is true if the file was an alias in the
Jack Jansen7aeba452003-02-12 09:58:33 +000058first place (otherwise the \class{FSSpec} object for the file itself
Fred Drake41788db1998-04-04 06:23:02 +000059is returned).
Jack Jansene4be9be1995-02-28 15:46:09 +000060\end{funcdesc}
61
Fred Drake4c6d21a2000-09-22 15:46:35 +000062\begin{funcdesc}{StandardGetFile}{\optional{type, \moreargs}}
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000063Present the user with a standard ``open input file''
Fred Drake41788db1998-04-04 06:23:02 +000064dialog. Optionally, you can pass up to four 4-character file types to limit
Jack Jansen7aeba452003-02-12 09:58:33 +000065the files the user can choose from. The function returns an \class{FSSpec}
Jack Jansene4be9be1995-02-28 15:46:09 +000066object and a flag indicating that the user completed the dialog
67without cancelling.
68\end{funcdesc}
69
Fred Drake4c6d21a2000-09-22 15:46:35 +000070\begin{funcdesc}{PromptGetFile}{prompt\optional{, type, \moreargs}}
Fred Drake41788db1998-04-04 06:23:02 +000071Similar to \function{StandardGetFile()} but allows you to specify a
Fred Drakeeecdc7f2000-10-14 04:45:22 +000072prompt which will be displayed at the top of the dialog.
Jack Jansen0e133741995-08-14 13:39:16 +000073\end{funcdesc}
74
Fred Drake4c6d21a2000-09-22 15:46:35 +000075\begin{funcdesc}{StandardPutFile}{prompt\optional{, default}}
Jack Jansene4be9be1995-02-28 15:46:09 +000076Present the user with a standard ``open output file''
77dialog. \var{prompt} is the prompt string, and the optional
Guido van Rossum6bb1adc1995-03-13 10:03:32 +000078\var{default} argument initializes the output file name. The function
Jack Jansen7aeba452003-02-12 09:58:33 +000079returns an \class{FSSpec} object and a flag indicating that the user
Fred Drake41788db1998-04-04 06:23:02 +000080completed the dialog without cancelling.
Jack Jansene4be9be1995-02-28 15:46:09 +000081\end{funcdesc}
82
Jack Jansen0e133741995-08-14 13:39:16 +000083\begin{funcdesc}{GetDirectory}{\optional{prompt}}
Fred Drakeeecdc7f2000-10-14 04:45:22 +000084Present the user with a non-standard ``select a directory'' dialog. You
85have to first open the directory before clicking on the ``select current
86directory'' button. \var{prompt} is the prompt string which will be
Jack Jansen7aeba452003-02-12 09:58:33 +000087displayed at the top of the dialog. Return an \class{FSSpec} object and
Fred Drakeeecdc7f2000-10-14 04:45:22 +000088a success-indicator.
Jack Jansene4be9be1995-02-28 15:46:09 +000089\end{funcdesc}
90
Guido van Rossum910a6711996-07-30 18:22:31 +000091\begin{funcdesc}{SetFolder}{\optional{fsspec}}
92Set the folder that is initially presented to the user when one of
Fred Drake41788db1998-04-04 06:23:02 +000093the file selection dialogs is presented. \var{fsspec} should point to
Guido van Rossum910a6711996-07-30 18:22:31 +000094a file in the folder, not the folder itself (the file need not exist,
95though). If no argument is passed the folder will be set to the
Fred Drake41788db1998-04-04 06:23:02 +000096current directory, i.e. what \function{os.getcwd()} returns.
Guido van Rossum910a6711996-07-30 18:22:31 +000097
Fred Drake6a002ca2003-09-05 14:01:15 +000098Note that starting with System 7.5 the user can change Standard File
Fred Drakeeecdc7f2000-10-14 04:45:22 +000099behaviour with the ``general controls'' control panel, thereby making
Guido van Rossum910a6711996-07-30 18:22:31 +0000100this call inoperative.
101\end{funcdesc}
102
Fred Drakecce10901998-03-17 06:33:25 +0000103\begin{funcdesc}{FindFolder}{where, which, create}
Fred Drake6a002ca2003-09-05 14:01:15 +0000104Locates one of the ``special'' folders that Mac OS knows about, such as
Fred Drake41788db1998-04-04 06:23:02 +0000105the trash or the Preferences folder. \var{where} is the disk to
106search, \var{which} is the 4-character string specifying which folder to
Jack Jansenda53c521995-10-10 14:43:20 +0000107locate. Setting \var{create} causes the folder to be created if it
Fred Drake41788db1998-04-04 06:23:02 +0000108does not exist. Returns a \code{(\var{vrefnum}, \var{dirid})} tuple.
Jack Jansen7aeba452003-02-12 09:58:33 +0000109
110The constants for \var{where} and \var{which} can be obtained from the
111standard module \var{Carbon.Folders}.
Fred Drake29996071997-08-22 13:45:13 +0000112\end{funcdesc}
Jack Jansenda53c521995-10-10 14:43:20 +0000113
Guido van Rossume229d861997-08-18 15:14:26 +0000114\begin{funcdesc}{NewAliasMinimalFromFullPath}{pathname}
Jack Jansen7aeba452003-02-12 09:58:33 +0000115Return a minimal \class{alias} object that points to the given file, which
Guido van Rossume229d861997-08-18 15:14:26 +0000116must be specified as a full pathname. This is the only way to create an
Jack Jansen7aeba452003-02-12 09:58:33 +0000117\class{Alias} pointing to a non-existing file.
Guido van Rossume229d861997-08-18 15:14:26 +0000118
Jack Jansene164bd81995-08-10 11:53:14 +0000119\end{funcdesc}
120
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000121\begin{funcdesc}{FindApplication}{creator}
Fred Drakeeecdc7f2000-10-14 04:45:22 +0000122Locate the application with 4-character creator code \var{creator}. The
Jack Jansen7aeba452003-02-12 09:58:33 +0000123function returns an \class{FSSpec} object pointing to the application.
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000124\end{funcdesc}
125
Fred Drakef6863c11999-03-02 16:37:17 +0000126
Fred Drakeefff11b2002-01-17 04:44:34 +0000127\subsection{FSSpec Objects \label{fsspec-objects}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000128
Fred Drake41788db1998-04-04 06:23:02 +0000129\begin{memberdesc}[FSSpec]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000130The raw data from the FSSpec object, suitable for passing
131to other applications, for instance.
Fred Drake41788db1998-04-04 06:23:02 +0000132\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000133
Fred Drake41788db1998-04-04 06:23:02 +0000134\begin{methoddesc}[FSSpec]{as_pathname}{}
Jack Jansen7aeba452003-02-12 09:58:33 +0000135Return the full pathname of the file described by the \class{FSSpec}
Fred Drake41788db1998-04-04 06:23:02 +0000136object.
137\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000138
Fred Drake41788db1998-04-04 06:23:02 +0000139\begin{methoddesc}[FSSpec]{as_tuple}{}
140Return the \code{(\var{wdRefNum}, \var{parID}, \var{name})} tuple of
Jack Jansen7aeba452003-02-12 09:58:33 +0000141the file described by the \class{FSSpec} object.
Fred Drake41788db1998-04-04 06:23:02 +0000142\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000143
Fred Drake41788db1998-04-04 06:23:02 +0000144\begin{methoddesc}[FSSpec]{NewAlias}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000145Create an Alias object pointing to the file described by this
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000146FSSpec. If the optional \var{file} parameter is present the alias
Jack Jansene4be9be1995-02-28 15:46:09 +0000147will be relative to that file, otherwise it will be absolute.
Fred Drake41788db1998-04-04 06:23:02 +0000148\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000149
Fred Drake41788db1998-04-04 06:23:02 +0000150\begin{methoddesc}[FSSpec]{NewAliasMinimal}{}
Jack Jansene4be9be1995-02-28 15:46:09 +0000151Create a minimal alias pointing to this file.
Fred Drake41788db1998-04-04 06:23:02 +0000152\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000153
Fred Drake41788db1998-04-04 06:23:02 +0000154\begin{methoddesc}[FSSpec]{GetCreatorType}{}
155Return the 4-character creator and type of the file.
156\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000157
Fred Drake41788db1998-04-04 06:23:02 +0000158\begin{methoddesc}[FSSpec]{SetCreatorType}{creator, type}
159Set the 4-character creator and type of the file.
160\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000161
Fred Drake41788db1998-04-04 06:23:02 +0000162\begin{methoddesc}[FSSpec]{GetFInfo}{}
Jack Jansen7aeba452003-02-12 09:58:33 +0000163Return a \class{FInfo} object describing the finder info for the file.
Fred Drake41788db1998-04-04 06:23:02 +0000164\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000165
Fred Drake41788db1998-04-04 06:23:02 +0000166\begin{methoddesc}[FSSpec]{SetFInfo}{finfo}
167Set the finder info for the file to the values given as \var{finfo}
Jack Jansen7aeba452003-02-12 09:58:33 +0000168(an \class{FInfo} object).
Fred Drake41788db1998-04-04 06:23:02 +0000169\end{methoddesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000170
Fred Drake41788db1998-04-04 06:23:02 +0000171\begin{methoddesc}[FSSpec]{GetDates}{}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000172Return a tuple with three floating point values representing the
173creation date, modification date and backup date of the file.
Fred Drake41788db1998-04-04 06:23:02 +0000174\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000175
Fred Drake41788db1998-04-04 06:23:02 +0000176\begin{methoddesc}[FSSpec]{SetDates}{crdate, moddate, backupdate}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000177Set the creation, modification and backup date of the file. The values
178are in the standard floating point format used for times throughout
179Python.
Fred Drake41788db1998-04-04 06:23:02 +0000180\end{methoddesc}
Guido van Rossum7e42cab1996-10-15 14:37:31 +0000181
Jack Jansene4be9be1995-02-28 15:46:09 +0000182
Fred Drakef6863c11999-03-02 16:37:17 +0000183\subsection{Alias Objects \label{alias-objects}}
Fred Drake41788db1998-04-04 06:23:02 +0000184
185\begin{memberdesc}[Alias]{data}
Jack Jansene4be9be1995-02-28 15:46:09 +0000186The raw data for the Alias record, suitable for storing in a resource
187or transmitting to other programs.
Fred Drake41788db1998-04-04 06:23:02 +0000188\end{memberdesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000189
Fred Drake41788db1998-04-04 06:23:02 +0000190\begin{methoddesc}[Alias]{Resolve}{\optional{file}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000191Resolve the alias. If the alias was created as a relative alias you
Guido van Rossum6bb1adc1995-03-13 10:03:32 +0000192should pass the file relative to which it is. Return the FSSpec for
Jack Jansen7aeba452003-02-12 09:58:33 +0000193the file pointed to and a flag indicating whether the \class{Alias} object
Guido van Rossume229d861997-08-18 15:14:26 +0000194itself was modified during the search process. If the file does
195not exist but the path leading up to it does exist a valid fsspec
196is returned.
Fred Drake41788db1998-04-04 06:23:02 +0000197\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000198
Fred Drake41788db1998-04-04 06:23:02 +0000199\begin{methoddesc}[Alias]{GetInfo}{num}
200An interface to the \C{} routine \cfunction{GetAliasInfo()}.
201\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000202
Fred Drake4c6d21a2000-09-22 15:46:35 +0000203\begin{methoddesc}[Alias]{Update}{file\optional{, file2}}
Jack Jansene4be9be1995-02-28 15:46:09 +0000204Update the alias to point to the \var{file} given. If \var{file2} is
205present a relative alias will be created.
Fred Drake41788db1998-04-04 06:23:02 +0000206\end{methoddesc}
Jack Jansene4be9be1995-02-28 15:46:09 +0000207
Fred Drake41788db1998-04-04 06:23:02 +0000208Note that it is currently not possible to directly manipulate a
Jack Jansen7aeba452003-02-12 09:58:33 +0000209resource as an \class{Alias} object. Hence, after calling
Fred Drake41788db1998-04-04 06:23:02 +0000210\method{Update()} or after \method{Resolve()} indicates that the alias
211has changed the Python program is responsible for getting the
Jack Jansen7aeba452003-02-12 09:58:33 +0000212\member{data} value from the \class{Alias} object and modifying the
Fred Drakedf0e3fc1998-04-07 20:04:27 +0000213resource.
Jack Jansene4be9be1995-02-28 15:46:09 +0000214
215
Fred Drakef6863c11999-03-02 16:37:17 +0000216\subsection{FInfo Objects \label{finfo-objects}}
Jack Jansene164bd81995-08-10 11:53:14 +0000217
Fred Drakee15eb351999-11-10 16:13:25 +0000218See \citetitle{Inside Macintosh: Files} for a complete description of what
Fred Drake41788db1998-04-04 06:23:02 +0000219the various fields mean.
Jack Jansene164bd81995-08-10 11:53:14 +0000220
Fred Drake41788db1998-04-04 06:23:02 +0000221\begin{memberdesc}[FInfo]{Creator}
222The 4-character creator code of the file.
223\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000224
Fred Drake41788db1998-04-04 06:23:02 +0000225\begin{memberdesc}[FInfo]{Type}
226The 4-character type code of the file.
227\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000228
Fred Drake41788db1998-04-04 06:23:02 +0000229\begin{memberdesc}[FInfo]{Flags}
Jack Jansenda53c521995-10-10 14:43:20 +0000230The finder flags for the file as 16-bit integer. The bit values in
Fred Drake41788db1998-04-04 06:23:02 +0000231\var{Flags} are defined in standard module \module{MACFS}.
232\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000233
Fred Drake41788db1998-04-04 06:23:02 +0000234\begin{memberdesc}[FInfo]{Location}
Jack Jansene164bd81995-08-10 11:53:14 +0000235A Point giving the position of the file's icon in its folder.
Fred Drake41788db1998-04-04 06:23:02 +0000236\end{memberdesc}
Jack Jansene164bd81995-08-10 11:53:14 +0000237
Fred Drake41788db1998-04-04 06:23:02 +0000238\begin{memberdesc}[FInfo]{Fldr}
Jack Jansene164bd81995-08-10 11:53:14 +0000239The folder the file is in (as an integer).
Fred Drake41788db1998-04-04 06:23:02 +0000240\end{memberdesc}