Inside Mac OS X
System Overview
July 2002
Apple Computer, Inc. and TrueType are trademarks of THE WARRANTY AND REMEDIES SET © 2000–2002 Apple Computer, Inc. Apple Computer, Inc., registered in FORTH ABOVE ARE EXCLUSIVE AND All rights reserved. the United States and other countries. IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No No part of this publication may be Carbon, Quartz, and Velocity Engine Apple dealer, agent, or employee is reproduced, stored in a retrieval are trademarks of Apple Computer, authorized to make any modification, system, or transmitted, in any form or Inc. extension, or addition to this warranty. by any means, mechanical, electronic, Enterprise Objects, Enterprise Objects photocopying, recording, or Framework, NeXT, Objective-rel="tag">C, and Some states do not allow the exclusion or otherwise, without prior written OpenStep are registered trademarks limitation of implied warranties or permission of Apple Computer, Inc., of NeXT Software, Inc., registered in liability for incidental or consequential with the following exceptions: Any the United States and other countries. damages, so the above limitation or person is hereby authorized to store Java and all Java-based trademarks exclusion may not apply to you. This documentation on a single computer are trademarks or registered warranty gives you specific legal rights, for personal use only and to print trademarks of Sun Microsystems, and you may also have other rights which copies of documentation for personal Inc., in the United States and other vary from state to state. use provided that the documentation countries. contains Apple’s copyright notice. Netscape Navigator is a trademark of The Apple logo is a trademark of Netscape Communications Apple Computer, Inc. Corporation. Use of the “keyboard” Apple logo OpenGL is a registered trademark of (Option-Shift-K) for commercial Silicon Graphics, Inc. purposes without the prior written consent of Apple may constitute PostScript is a trademark of Adobe trademark infringement and unfair Systems Incorporated. competition in violation of federal PowerPC is a trademark of and state laws. International Business Machines No licenses, express or implied, are Corporation, used under license granted with respect to any of the therefrom. technology described in this book. Simultaneously published in the Apple retains all intellectual property United States and Canada. rights associated with the technology Even though Apple has reviewed this described in this book. This book is manual, APPLE MAKES NO intended to assist application WARRANTY OR REPRESENTATION, developers to develop applications EITHER EXPRESS OR IMPLIED, WITH only for Apple-labeled or RESPECT TO THIS MANUAL, ITS Apple-licensed computers. QUALITY, ACCURACY, Every effort has been made to ensure MERCHANTABILITY, OR FITNESS that the information in this document FOR A PARTICULAR PURPOSE. AS A is accurate. Apple is not responsible RESULT, THIS MANUAL IS SOLD “AS for typographical errors. IS,” AND YOU, THE PURCHASER, ARE Apple Computer, Inc. ASSUMING THE ENTIRE RISK AS TO 1 Infinite Loop ITS QUALITY AND ACCURACY. Cupertino, CA 95014 IN NO EVENT WILL APPLE BE LIABLE 408-996-1010 FOR DIRECT, INDIRECT, SPECIAL, Apple, the Apple logo, AirPort, INCIDENTAL, OR CONSEQUENTIAL AppleScript, AppleShare, AppleTalk, DAMAGES RESULTING FROM ANY Aqua, Cocoa, ColorSync,Finder, DEFECT OR INACCURACY IN THIS FireWire, iBook, iMac, Mac, MANUAL, even if advised of the Macintosh, Power Mac, QuickDraw, possibility of such damages. QuickTime, PowerBook, Sherlock,
Contents
Figures, Listings, and Tables 13
Chapter 1 About This Book 17 Why Read This Book 17 Further Investigations 19 Installed Developer Documentation 19 Other Apple Publications 20 Information on BSD 21 Other Information on the Web 21
Chapter 2 System Technologies 23 The User Experience 24 Aqua 25 The Finder 26 Application Support 28 Multiple Users 29 Internationalization 30 Accessibility 30 AppleScript 31 Exported Application Services 32 Other Parts of the User Experience 32 Darwin 33 Mach 33 BSD 34 Device-Driver Support 35 Networking Extensions 35 File Systems 36 Darwin and Open Source Development 38
3 Apple Computer, Inc. July 2002
CONTENTS
Graphics and Imaging 38 Quartz 38 QuickDraw 40 OpenGL 41 QuickTime 41 Printing 42 Apple Type Solution 43 Application Technologies 43 Application Extensibility 44 Disc Recording 45 Contact Database 45 Networking and the Internet 46 Media Types 46 Standard Protocols 47 Legacy Network Services and Protocols 48 Rendezvous 49 Routing and Multihoming 49 Personal File and Web Services 49 Advanced Hardware Features 50 USB 50 FireWire 51 Velocity Engine 51 AirPort 51 Video Features 52
Chapter 3 System Architecture 53 A Layered Perspective 54 Application Environments 59 Carbon 60 Cocoa 63 Java 64 The Graphics and Windowing Environment 67 Quartz Compositor 69 Quartz 2D 70
4 Apple Computer, Inc. July 2002
CONTENTS
The Printing System 72 The User Interface of the Printing System 73 Summary of Printing Architecture 74 Printer Discovery 76 The Printing Process 76 Other Application Services 77 Process Manager 78 Carbon Event Manager 78 Apple Events 78 The Clipboard 79 Core Services 79 Core Foundation 79 Carbon Core 82 CFNetwork 83 Web Services 84 Open Transport 84 Tracking a User Event 85
Chapter 4 Booting and Logging In 89 The Boot Sequence 89 BootROM 90 BootX 90 System Initialization 91 The rc.boot and rc Scripts 92 Startup Items 93 System Daemons 96 Launching Daemons on Demand 99 Managing User Sessions 100 Logging In 100 Authenticating Users 101 Setting Up the User Environment 102 Logging Out 102 Application Responsibilities 103 Terminating Processes 104
5 Apple Computer, Inc. July 2002
CONTENTS
Customization Techniques 105 Creating Custom Startup Items 105 Creating the Startup Item Executable 106 Specifying the Startup Item Properties 107 Starting and Stopping Startup Items 109 Customizing Login and Logout Procedures 110 Using Environment Variables 112 Replacing the Finder 112
Chapter 5 Bundles 115 Benefits of Using Bundles 116 Anatomy of a Bundle 117 The Finder and Bundles 122 Types of Bundles 123 An Application’s Main Bundle 124 Framework Bundles 124 Loadable Bundles and Dynamic Linking 124 Localized Resources 125 Localized Character Strings 126 Search Algorithm 127 Bundles and the Resource Manager 129
Chapter 6 Application Packaging 131 An Application Is a Bundle 131 Application Frameworks, Libraries, and Helpers 133 Private Frameworks 134 Shared Frameworks and the Central Directory 135 Other Shared Application Code 136 Applications and Loadable Bundles 137 User Resources in Applications 138 Application Help 138 Application Preferences 139 Document Resources 140
6 Apple Computer, Inc. July 2002
CONTENTS
Chapter 7 Frameworks 141 The Framework as a Library Package 142 The Internal Structure of Frameworks 143 Standard Locations for Frameworks 145 Dynamic Shared Libraries 146 Framework Versioning 148 Major Versions 148 Minor Versions 150 Versioning Summary and Guidelines 151
Chapter 8 Umbrella Frameworks 155 Kinds of Frameworks 156 The Purpose of Umbrella Frameworks 157 Linking and Including Guideline 159 The Structure of an Umbrella Framework 160 Restrictions on Subframework Linking 162
Chapter 9 The File System 165 How the File System Is Organized 165 File-System Domains 167 The User Domain 168 The Local Domain 170 The Network Domain 171 The System Domain 172 The Library Directory 172 The Developer Directory 174 Directories of the Classic Environment 176 Searching Within the File-System Domains 177 Hiding Filename Extensions 177 Localizing File System Names 178 Displaying Localized Path Names 179 Localizing Bundle Names 179 Localizing Directory Names 180
7 Apple Computer, Inc. July 2002
CONTENTS
Differences Between HFS+ and UFS 181 Aliases and Symbolic Links 182 Resource Forks 183 File Encodings and Fonts 186
Chapter 10 The Finder 189 The Role of the Finder 189 Finder Interfaces to Applications 191 Apple Events 191 Information Property Lists 191 Information Stored by the Finder 192 Collecting Application Information 192 The Desktop Folder 193 Finder Attributes 194 The Handling of Applications and Documents 194 Presenting Documents 195 Sorting Files 196 Choosing Applications to Launch 196 The Finder and File Operations 197 Copy and Move Operations 197 Management of Aliases and Symbolic Links 198
Chapter 11 Software Configuration 199 Property Lists 199 Information Property Lists 200 Document Configuration 201 An Example of an Information Property List 202 The Preferences System 205 How Preferences Are Stored 206 Preference Domains 207 The defaults Utility 208
8 Apple Computer, Inc. July 2002
CONTENTS
Chapter 12 Internationalization 211 Internationalizing Your Application 212 Language Preferences and Bundle Resources 213 Designating Languages and Locales 215 Tools for Internationalization and Localization 216 Localizing User Interfaces 218 Localizing Strings 219 Composing a Strings File 220 Generating Strings Files 222 Adding Multiscript Support 222
Chapter 13 Installation and Integration 225 Preparing Software for Mac OS X 225 Applications and Documents FAQ 226 What metadata must I specify for an application? 226 Must I package my CFM executable in a bundle? 227 How should I store application resources? 227 How do I indicate document types in Mac OS X? 229 Can I treat my plug-ins as documents? 229 How does the Finder handle documents? 229 Why even have extensions? 230 How should my application save documents? 231 CFM Executables 231 User Interface Issues 234 Icons 235 Custom Controls and System Appearance 235 Carbon Nib Files 236 Ownership and Permissions 236 Overview of BSD Permissions 237 File Permissions in Mac OS X 240 Permissions for Applications and Documents 241 The Classic Environment and Your Application 241 Overview of the Classic Environment 242 Compatibility With Native Mac OS 9 243 Device Support 243
9 Apple Computer, Inc. July 2002
CONTENTS
Integration With Mac OS X 244 User Interface 245 The Classic Environment and File Systems 245 Extensions and Preferences 246 The Finder and the Desktop 247 Networking and Printing 248 Other Classic Integration Issues 249 Installing Your Application 249 Where to Install 249 Manual Installation 250 Installers 251 Installation Packages 253 Creating an Installation Package 254 System-Wide Resources 257
Chapter 14 Issues and Options With Multiple Environments 259 Tasks and Processes 259 Threading Packages 260 Layering Details 262 Usage Guidelines 262 Interprocess Communication 263 Communicating With Apple Events 264 Broadcasting Simple Notifications 265 Transferring Raw Data With CFMessagePort 265 Communicating With BSD Sockets 265 Communicating With BSD Pipes 266 Handling Exceptions With BSD Signals 267 Sharing Large Resources With Shared Memory 267 Making Services Available to Other Applications 268 Calling Other Processes With Distributed Objects 268 Messaging With the Mach Port Object 268 Library Managers and Executable Formats 269 Comparing the Runtime Environments 269 CFM and dyld 270 PEF and Mach-O 270 Code-Generation Models 270
10 Apple Computer, Inc. July 2002
CONTENTS
Vector Libraries 271 CFM Executable and Non-Carbon APIs 272 Should You Use CFM or dyld? 272
Appendix A Information Property List Keys 275 Bundle Keys 275 Standard Bundle Keys 276 CFBundleDevelopmentRegion 277 CFBundleDisplayName 277 CFBundleDocumentTypes 278 CFBundleExecutable 279 CFBundleGetInfoHTML 280 CFBundleGetInfoString 280 CFBundleHelpBookFolder 280 CFBundleHelpBookName 280 CFBundleIconFile 281 CFBundleIdentifier 281 CFBundleInfoDictionaryVersion 281 CFBundleName 281 CFBundlePackageType 282 CFBundleShortVersionString 282 CFBundleSignature 282 CFBundleURLTypes 283 CFBundleVersion 284 Application-Specific Keys 284 CFAppleHelpAnchor 285 NSAppleScriptEnabled 285 NSHumanReadableCopyright 285 NSJavaNeeded 285 NSJavaPath 286 NSJavaRoot 286 NSMainNibFile 286 NSPrincipalClass 286 NSServices 287
11 Apple Computer, Inc. July 2002
CONTENTS
Launch Services Keys 289 LSBackgroundOnly 290 LSPrefersCarbon 290 LSPrefersClassic 290 LSRequiresCarbon 291 LSRequiresClassic 291 LSUIElement 291 Application Package Keys 292 CFBundleInstallerInfo 292 APInstallerURL 292 APFiles 293
Glossary 295
Index 309
12 Apple Computer, Inc. July 2002
Figures, Listings, and Tables
Chapter 2 System Technologies 23 Figure 2-1 A functional view of Mac OS X 24 Figure 2-2 The Aqua user interface 25 Table 2-1 Supported local volume formats 36 Table 2-2 Supported network file protocols 37 Table 2-3 Quartz graphics capabilities and specifications 39 Table 2-4 Features of the Mac OS X printing system 42 Table 2-5 Network media types 46 Table 2-6 Network protocols 47
Chapter 3 System Architecture 53 Figure 3-1 Mac OS X as layers of system software 55 Figure 3-2 Architecture of the Java environment 66 Figure 3-3 Quartz and the graphics and windowing environment 68 Figure 3-4 The Core Graphics framework 69 Figure 3-5 Quartz 2D inputs and outputs 71 Figure 3-6 Mac OS X printing system 74 Figure 3-7 The handling of an event in Mac OS X 86 Table 3-1 Required Manager replacements for Carbon 61 Table 3-2 Recommended Manager replacements for Carbon 61 Table 3-3 Core Foundation services 80 Table 3-4 Carbon managers in the Core Services layer 82
Chapter 4 Booting and Logging In 89 Figure 4-1 Processes shown in Process Viewer 97 Figure 4-2 The Login Options pane of Accounts system preferences 110 Table 4-1 Core system startup items 94 Table 4-2 Common system daemons and servers 98 Table 4-3 StartupParameters.plist key-value pairs 108
13 Apple Computer, Inc. July 2002
FIGURES, LISTINGS, AND TABLES
Table 4-4 loginwindow parameters 111
Chapter 5 Bundles 115 Figure 5-1 The Finder’s bundle bit 122 Figure 5-2 Locating a resource in a bundle 128 Listing 5-1 A minimal bundle 118 Listing 5-2 The bundle layout of a complex application 119
Chapter 6 Application Packaging 131 Listing 6-1 Location of an application’s private framework 134 Listing 6-2 Location of an application’s shared framework 135 Listing 6-3 Location of an application’s shared code (nonframework) 136
Chapter 7 Frameworks 141 Figure 7-1 The directory structure of a framework 144 Figure 7-2 Lazy linking of dynamic shared library modules 147 Table 7-1 Summary of framework versioning 152
Chapter 8 Umbrella Frameworks 155 Figure 8-1 The relationship between an umbrella framework and its subframeworks 158 Listing 8-1 Structure of an umbrella framework 161
Chapter 9 The File System 165 Figure 9-1 Resources in the data fork 185 Listing 9-1 The top level of a sample Mac OS X file system 166 Table 9-1 Uses of tilde to indicate locations in home directories 169 Table 9-2 Default home directory contents 169 Table 9-3 Network directories 171
14 Apple Computer, Inc. July 2002
FIGURES, LISTINGS, AND TABLES
Table 9-4 Subdirectories of the /Library directory 173 Table 9-5 Developer subdirectory contents 175 Table 9-6 Directories created by the Mac OS 9.1 (or later) installer 176
Chapter 11 Software Configuration 199 Listing 11-1 The Info.plist file for the Sketch demo application 202 Listing 11-2 The InfoPlist.strings file for the Sketch demo application 205 Table 11-1 Preference domains in search order 208
Chapter 12 Internationalization 211 Figure 12-1 Language pane of the System Preferences International module 214 Figure 12-2 Project Builder’s File Reference Inspector 217
Chapter 13 Installation and Integration 225 Figure 13-1 Installer application 252 Figure 13-2 The Package Maker user interface 256 Table 13-1 Types of applications supported in Mac OS X 232 Table 13-2 File permission mappings 239
Chapter 14 Issues and Options With Multiple Environments 259 Figure 14-1 Threading packages in Mac OS X 261 Figure 14-2 A Carbon application calling BSD system routines 272
Appendix A Information Property List Keys 275 Table A-1 Summary of standard keys 276 Table A-2 Keys for CFBundleDocumentTypes dictionaries 278 Table A-3 Keys for CFBundleURLTypes dictionaries 283 Table A-4 Application-specific keys 284
15 Apple Computer, Inc. July 2002
FIGURES, LISTINGS, AND TABLES
Table A-5 Keys for NSServices dictionaries 287 Table A-6 Launch Services keys 289 Table A-7 Application packaging keys 292 Table A-8 Keys for APFiles dictionary 293
16 Apple Computer, Inc. July 2002
CHAPTER 1
1 About This Book
Apple Computer’s Mac OS X operating system is the most revolutionary operating system to hit the computer scene in many years. With Mac OS X, Apple has reasserted its leadership not only in operating systems but in the technological sophistication and design sensibility that are the hallmarks of the company. While preserving the famed ease-of-use and personality of its predecessors, Mac OS X is an industrial-strength, modern operating system engineered for reliability, stability, scalability, and performance. As such, it lays the foundation for another decade of innovation.
This book introduces software developers to Mac OS X. It describes the operating system’s features and architecture. And it explains some of the concepts and conventions of Mac OS X that are of interest to those developing software for the platform.
Why Read This Book
Inside Mac OS X: System Overview is intended for anyone who wants to develop software for Mac OS X. But it is also a resource for people who are just curious about Mac OS X as a development and deployment platform. Whether your background is software development for Mac OS 9, UNIX, Windows, Java, or any other platform, you are likely to find something of value in this book.
Why Read This Book 17 Apple Computer, Inc. July 2002
CHAPTER 1
About This Book
This book describes the Mac OS X operating system from both a functional and architectural perspective and explains some of the concepts, services, and conventions common to the three primary development environments: Carbon, Cocoa, and Java. The book attempts to be “API-agnostic,” avoiding as much as possible details specific to a programming interface or application environment.
The book has the following chapters: System Technologies. Describes the user experience and summarizes the features and capabilities of the operating system, including the core operating system called Darwin, the graphics and windowing system, and supported networking services and protocols. System Architecture. Provides a high-level discussion of the design of Mac OS X, describing the various layers of system software. Also explains how events are handled and discusses some general programming issues. Booting and Logging In. Describes the sequence of actions that occur when a Mac OS X system boots and when users log into the system. Also shows how you can customize the booting and login sequences. Bundles. Describes bundles, the basic packaging model for software on Mac OS X. Application Packaging. Offers details of application bundles and how they package their various resources. Frameworks. Describes frameworks, another type of bundle, which are used to package dynamic shared libraries and their supporting resources. Umbrella Frameworks. Provides information about umbrella frameworks, the primary model for packaging Apple-provided frameworks. The File System. Discusses topics related to the file system, such as the standard directory layout, resource forks, and differences between the major volume formats. The Finder. Describes the interfaces between the Finder and applications and explains how the Finder handles various tasks, such as determining application ownership of documents and copying files between volumes of different formats. Software Configuration. Describes the basic mechanisms for configuring applications and other bundles and for handling user preferences. Internationalization. Explains how to prepare your application for localization and how to enable it to display multiscript text.
18 Why Read This Book Apple Computer, Inc. July 2002
CHAPTER 1
About This Book