Sign in Join
Wiki copytemporary

Application Bundle: what changed

Revision 4 to 5. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Overview
22
33An application bundle is a directory with the extension ".app" on macOS systems. It contains the application executable, resource files, library files (if any), help files and information about the application and is necessary for the correct execution of applications. The Mac Finder treats this .app directory as the application file and by default does not show any of its sub-directories.
44
55From within Lazarus it is used for the [[Carbon Interface|Carbon]] and [[Cocoa Interface|Cocoa]] interfaces, but one can also build applications with other interfaces (eg Gtk or Qt) by using scripts.
66
77You can learn more about application bundles in the Apple Bundle Programming Guide.
88
99Application (bundle) settings are located in the property list file: [[macOS property list files|Info.plist]] located in the `bundle.app/Contents/` directory.
1010
1111The **PkgInfo** file is an alternative way to specify the type and creator codes of your application or bundle. This file is not required, but can improve performance for code that accesses this information. Regardless of whether you provide this file, you should always include type and creator information in your information property list file using the CFBundlePackageType and CFBundleSignature keys, respectively. The contents of the PkgInfo file are the 4-byte package type followed by the 4-byte signature of your application. Thus, for the TextEdit application, whose type is 'APPL' and whose signature is 'ttxt', the file would contain the ASCII string “APPLttxt”.
1212
1313To access the application bundle contents in Finder, you need to right click (ctrl-left click) on a bundle and select *Show Package Contents*
1414
1515![](/wiki-images/1/12/Openbundle.png)
1616
1717![](/wiki-images/8/81/Infoplist.png)
1818
1919## Application bundle layout
2020
2121The basic structure of a Mac application bundle:
2222
23-`MyApp.app/`\
24-`   Contents/`\
25-`      Info.plist`\
26-`      MacOS/`\
27-`      PkgInfo`\
28-`      Resources/`
23+```
24+MyApp.app/
25+ Contents/
26+ Info.plist
27+ MacOS/
28+ PkgInfo
29+ Resources/
30+```
2931
3032| Sub-Directory of the Contents directory | Usage description |
3133|----|----|
3234| MacOS | (Required) Contains the application’s standalone executable code. Typically, this directory contains only one binary file with your application’s main entry point and statically linked code. However, you may put other standalone executables (such as command-line tools) in this directory as well. |
3335| Resources | Contains all of the application’s resource files. The contents of this directory are further organized to distinguish between localized and nonlocalized resources. For more information about the structure of this directory, see [[Add an Apple Help Book to your macOS app|Adding a Help Book - Bundle layouts]]. |
3436| Frameworks | Contains any private shared libraries and frameworks used by the executable. The frameworks in this directory are revision-locked to the application and cannot be superseded by any other, even newer, versions that may be available to the operating system. In other words, the frameworks included in this directory take precedence over any other similarly named frameworks found in other parts of the operating system. For information on how to add shared libraries to your application bundle, see [[macOS Dynamic Libraries]]. |
3537| PlugIns | Contains loadable bundles that extend the basic features of your application. You use this directory to include code modules that must be loaded into your application’s process space in order to be used. You would not use this directory to store standalone executables. |
3638| SharedSupport | Contains additional non-critical resources that do not impact the ability of the application to run. You might use this directory to include things like document templates, clip art, and tutorials that your application expects to be present but that do not affect the ability of your application to run. |
3739
3840## Creating the Application Bundle
3941
4042### Using Lazarus
4143
4244Open a project in the Lazarus IDE and go to Project -\> Project Options -\> Application tab and push the [[IDE Window: Project Options|Create Application Bundle]] button. The resulting Application Bundle will contain a symbolic link to the real executable.
4345
4446> **Note:** You must remove the symbolic link and copy the real executable "project1" into the `project1.app/Contents/MacOS/` directory to distribute the application and use it on another computer.
4547
4648### Using the Lazarus command-line tool
4749
4850Open `/Applications/Lazarus/components/macfiles/examples/createmacapplication.lpi` in the Lazarus IDE. Compile.
4951
5052Open a Terminal of your choice and type:
5153
5254``` bash
5355cd project1/
5456/Applications/Lazarus/components/macfiles/examples/createmacapplication project1
5557ln -s ../../../project1 project1.app/Contents/MacOS/project1
5658```
5759
5860### Using a shell script
5961
6062You can adapt the following shell script to create a customized application bundle for your application. It allows the creation of either a debug or a release bundle.
6163
6264- In the debug bundle, a link to the executable is placed, allowing for debugging using the Lazarus IDE,
6365- In the release bundle, the executable is copied so the application bundle as a whole can be used stand-alone/copied to other locations.
6466
6567``` bash
6668#!/bin/sh
6769# Force Bourne shell in case tcsh is default.
6870#
6971
7072#
7173# Reads the bundle type
7274#
7375
7476echo "========================================================"
7577echo " Bundle creation script"
7678echo "========================================================"
7779echo ""
7880echo " Please select which kind of bundle you would like to build:"
7981echo ""
8082echo " 1 > Debug bundle"
8183echo " 2 > Release bundle"
8284echo " 0 > Exit"
8385
8486read command
8587
8688case $command in
8789
8890 1) ;;
8991
9092 2) ;;
9193
9294 0) exit 0;;
9395
9496 *) echo "Invalid command"
9597 exit 0;;
9698
9799esac
98100
99101#
100102# Creates the bundle
101103#
102104
103105appname=Magnifier
104106appfolder=$appname.app
105107macosfolder=$appfolder/Contents/MacOS
106108plistfile=$appfolder/Contents/Info.plist
107109appfile=magnifier
108110
109111PkgInfoContents="APPL????"
110112
111113#
112114if ! [ -e $appfile ]
113115then
114116 echo "$appfile does not exist"
115117elif [ -e $appfolder ]
116118then
117119 echo "$appfolder already exists"
118120else
119121 echo "Creating $appfolder..."
120122 mkdir $appfolder
121123 mkdir $appfolder/Contents
122124 mkdir $appfolder/Contents/MacOS
123125 mkdir $appfolder/Contents/Frameworks # optional, for including libraries or frameworks
124126 mkdir $appfolder/Contents/Resources
125127
126128#
127129# For a debug bundle,
128130# Instead of copying executable into .app folder after each compile,
129131# simply create a symbolic link to executable.
130132#
131133if [ $command = 1 ]; then
132134 ln -s ../../../$appname $macosfolder/$appname
133135else
134136 cp $appname $macosfolder/$appname
135137fi
136138
137139# Copy the resource files to the correct place
138140 cp *.bmp $appfolder/Contents/Resources
139141 cp icon3.ico $appfolder/Contents/Resources
140142 cp icon3.png $appfolder/Contents/Resources
141143 cp macicon.icns $appfolder/Contents/Resources
142144 cp docs/*.* $appfolder/Contents/Resources
143145#
144146# Create PkgInfo file.
145147 echo $PkgInfoContents >$appfolder/Contents/PkgInfo
146148#
147149# Create information property list file (Info.plist).
148150 echo '<?xml version="1.0" encoding="UTF-8"?>' >$plistfile
149151 echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >>$plistfile
150152 echo '<plist version="1.0">' >>$plistfile
151153 echo '<dict>' >>$plistfile
152154 echo ' <key>CFBundleDevelopmentRegion</key>' >>$plistfile
153155 echo ' <string>English</string>' >>$plistfile
154156 echo ' <key>CFBundleExecutable</key>' >>$plistfile
155157 echo ' <string>'$appname'</string>' >>$plistfile
156158 echo ' <key>CFBundleIconFile</key>' >>$plistfile
157159 echo ' <string>macicon.icns</string>' >>$plistfile
158160 echo ' <key>CFBundleIdentifier</key>' >>$plistfile
159161 echo ' <string>org.magnifier.magnifier</string>' >>$plistfile
160162 echo ' <key>CFBundleInfoDictionaryVersion</key>' >>$plistfile
161163 echo ' <string>6.0</string>' >>$plistfile
162164 echo ' <key>CFBundlePackageType</key>' >>$plistfile
163165 echo ' <string>APPL</string>' >>$plistfile
164166 echo ' <key>CFBundleSignature</key>' >>$plistfile
165167 echo ' <string>MAG#</string>' >>$plistfile
166168 echo ' <key>CFBundleVersion</key>' >>$plistfile
167169 echo ' <string>1.0</string>' >>$plistfile
168170 echo '</dict>' >>$plistfile
169171 echo '</plist>' >>$plistfile
170172fi
171173```
172174
173175## Executing an application via the Application Bundle
174176
175177You can start the application from the Lazarus IDE, by clicking on its Finder icon or in the native macOS Terminal.app by typing:
176178
177179``` bash
178180open project1.app
179181```
180182
181183or
182184
183185``` bash
184186./project1.app/Contents/MacOS/project1
185187```
186188
187189## See also
188190
189191- [[Add an Apple Help Book to your macOS app]]
190192- [[Deploying Your Application|Deploying your macOS application]]
191193- [[Hiding a macOS app from the Dock]]
192194- [[macOS property list files]]
193195
194196## External links
195197
196198- [Apple: NSBundle class](https://developer.apple.com/documentation/foundation/nsbundle)
197199- [Apple: Bundle Resources](https://developer.apple.com/documentation/bundleresources/)
198200- [Apple: CFBundle](https://developer.apple.com/documentation/corefoundation/cfbundle)
199201- [Apple: Bundle Configuration](https://developer.apple.com/documentation/bundleresources/information_property_list/bundle_configuration)
200202- [Apple: Resource Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LoadingResources/Introduction/Introduction.html)
201203- [Apple: Bundle Programming Guide](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html)
202204
203205---
204206*From the Free Pascal wiki, page "Application Bundle", as it stood on 2022-03-13 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history