Displaying the File and Creator Types of Files
It is
often important to get the file type and creator type of files. These
are actually two properties of the file
object,
which is a class that the Finder application makes available to
AppleScripters. The file type
is specifically a
four-character name for the kind of file, such as
'TEXT'
for a simple text file or
'APPL'
for an application file that will execute a
program if you double-click it.
Warning
The Mac OS X
file system supports “file types,”
but their use is optional and some files may not have a file type.
Some files will instead be identified by their extension, as in
textfile.txt or
myapplication.app. Apple Computer suggests that
scripts which rely on file types for identifying certain files should
be augmented to include a check for certain extensions. For example,
if the script is looking for all files that are pict, gif, or jpeg
image files, then it should check for file types (e.g.,
'PICT'
, 'GIFf'
, or
'JPEG'
) and certain
extensions (e.g., .pct,
.gif, or .jpg).
The creator type
is a four-character name for the
program that will try to open the file if you double-click the file.
For example, if the file has a creator
type
of 'ttxt'
then SimpleText
tries to handle it; a creator type
of
'R*ch'
opens BBEdit if you double-click the file.
The following script is a droplet that will display the file type
and creator type
of any
file
you drag and drop on the
droplet’s icon. Figure 14-3 shows what this dialog box looks like. ...
Get AppleScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.