How to reliably get an application's creator type on MacOS X
How to reliably get an application's creator type on MacOS X
- Subject: How to reliably get an application's creator type on MacOS X
- From: Mark Alldritt <email@hidden>
- Date: Wed, 11 Apr 2001 09:46:45 -0700
Hi Folks,
As far as I can tell, the "info for" command in StandardAdditions and the
Finder's creator type property cannot be used to determine the creator type
(i.e. Signature) of a bundled application on MacOS X (e.g. Mail.app).
Here's some code that uses my XML Tools scripting addition to reliably get
the creator type of an application:
on getCreatorType(theAppFile)
try
return file creator of (info for theAppFile)
on error
-- its a bundled applicaton which we cannot seem to get the file
-- type for (both the Finder and info for fail to return creator
-- types for bundled applications). The code below extracts the
-- creator type from the application's "plist" (Property list).
-- This is an XML file that contains all the meta information
-- that lived in the file system under the Classic MacOS.
local creatorType
set creatorType to "????" -- in case the plist does not specify it
tell application "Finder" to set theAppFile to theAppFile as string
set theXML to XML contents of item 1 of XML contents of (parse XML
(read file (theAppFile & "Contents:info.plist")))
repeat with i from 1 to length of theXML
local anElement
set anElement to item i of theXML
if XML tag of anElement is "key" and item 1 of XML contents of
anElement is "CFBundleSignature" then
set creatorType to item 1 of XML contents of item (i + 1) of
theXML
exit repeat
end if
end repeat
return creatorType
end try
end getCreatorType
getCreatorType(choose file)
The XML Tools scripting addition is available from
<
http://www.latneightsw.com/freeware/XMLTools2/>.
Cheers
-Mark
---------------------------------------------------------------------
Mark Alldritt Late Night Software Ltd.
Phone: 250-380-1725 333 Moss Street
FAX: 250-383-3204 Victoria, B.C.
WEB:
http://www.latenightsw.com/ CANADA V8V-4M9