Sign in Join
Wiki copytemporary

Application Bundle: what changed

Revision 5 to 6. 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-```
23+```text
2424MyApp.app/
2525 Contents/
2626 Info.plist
2727 MacOS/
2828 PkgInfo
2929 Resources/
3030```
3131
3232| Sub-Directory of the Contents directory | Usage description |
3333|----|----|
3434| 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. |
3535| 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]]. |
3636| 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]]. |
3737| 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. |
3838| 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. |
3939
4040## Creating the Application Bundle
4141
4242### Using Lazarus
4343
4444Open 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.
4545
4646> **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.
4747
4848### Using the Lazarus command-line tool
4949
5050Open `/Applications/Lazarus/components/macfiles/examples/createmacapplication.lpi` in the Lazarus IDE. Compile.
5151
5252Open a Terminal of your choice and type:
5353
5454``` bash
5555cd project1/
5656/Applications/Lazarus/components/macfiles/examples/createmacapplication project1
5757ln -s ../../../project1 project1.app/Contents/MacOS/project1
5858```
5959
6060### Using a shell script
6161
6262You 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.
6363
6464- In the debug bundle, a link to the executable is placed, allowing for debugging using the Lazarus IDE,
6565- In the release bundle, the executable is copied so the application bundle as a whole can be used stand-alone/copied to other locations.
6666
6767``` bash
6868#!/bin/sh
6969# Force Bourne shell in case tcsh is default.
7070#
7171
7272#
7373# Reads the bundle type
7474#
7575
7676echo "========================================================"
7777echo " Bundle creation script"
7878echo "========================================================"
7979echo ""
8080echo " Please select which kind of bundle you would like to build:"
8181echo ""
8282echo " 1 > Debug bundle"
8383echo " 2 > Release bundle"
8484echo " 0 > Exit"
8585
8686read command
8787
8888case $command in
8989
9090 1) ;;
9191
9292 2) ;;
9393
9494 0) exit 0;;
9595
9696 *) echo "Invalid command"
9797 exit 0;;
9898
9999esac
100100
101101#
102102# Creates the bundle
103103#
104104
105105appname=Magnifier
106106appfolder=$appname.app
107107macosfolder=$appfolder/Contents/MacOS
108108plistfile=$appfolder/Contents/Info.plist
109109appfile=magnifier
110110
111111PkgInfoContents="APPL????"
112112
113113#
114114if ! [ -e $appfile ]
115115then
116116 echo "$appfile does not exist"
117117elif [ -e $appfolder ]
118118then
119119 echo "$appfolder already exists"
120120else
121121 echo "Creating $appfolder..."
122122 mkdir $appfolder
123123 mkdir $appfolder/Contents
124124 mkdir $appfolder/Contents/MacOS
125125 mkdir $appfolder/Contents/Frameworks # optional, for including libraries or frameworks
126126 mkdir $appfolder/Contents/Resources
127127
128128#
129129# For a debug bundle,
130130# Instead of copying executable into .app folder after each compile,
131131# simply create a symbolic link to executable.
132132#
133133if [ $command = 1 ]; then
134134 ln -s ../../../$appname $macosfolder/$appname
135135else
136136 cp $appname $macosfolder/$appname
137137fi
138138
139139# Copy the resource files to the correct place
140140 cp *.bmp $appfolder/Contents/Resources
141141 cp icon3.ico $appfolder/Contents/Resources
142142 cp icon3.png $appfolder/Contents/Resources
143143 cp macicon.icns $appfolder/Contents/Resources
144144 cp docs/*.* $appfolder/Contents/Resources
145145#
146146# Create PkgInfo file.
147147 echo $PkgInfoContents >$appfolder/Contents/PkgInfo
148148#
149149# Create information property list file (Info.plist).
150150 echo '<?xml version="1.0" encoding="UTF-8"?>' >$plistfile
151151 echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >>$plistfile
152152 echo '<plist version="1.0">' >>$plistfile
153153 echo '<dict>' >>$plistfile
154154 echo ' <key>CFBundleDevelopmentRegion</key>' >>$plistfile
155155 echo ' <string>English</string>' >>$plistfile
156156 echo ' <key>CFBundleExecutable</key>' >>$plistfile
157157 echo ' <string>'$appname'</string>' >>$plistfile
158158 echo ' <key>CFBundleIconFile</key>' >>$plistfile
159159 echo ' <string>macicon.icns</string>' >>$plistfile
160160 echo ' <key>CFBundleIdentifier</key>' >>$plistfile
161161 echo ' <string>org.magnifier.magnifier</string>' >>$plistfile
162162 echo ' <key>CFBundleInfoDictionaryVersion</key>' >>$plistfile
163163 echo ' <string>6.0</string>' >>$plistfile
164164 echo ' <key>CFBundlePackageType</key>' >>$plistfile
165165 echo ' <string>APPL</string>' >>$plistfile
166166 echo ' <key>CFBundleSignature</key>' >>$plistfile
167167 echo ' <string>MAG#</string>' >>$plistfile
168168 echo ' <key>CFBundleVersion</key>' >>$plistfile
169169 echo ' <string>1.0</string>' >>$plistfile
170170 echo '</dict>' >>$plistfile
171171 echo '</plist>' >>$plistfile
172172fi
173173```
174174
175175## Executing an application via the Application Bundle
176176
177177You can start the application from the Lazarus IDE, by clicking on its Finder icon or in the native macOS Terminal.app by typing:
178178
179179``` bash
180180open project1.app
181181```
182182
183183or
184184
185185``` bash
186186./project1.app/Contents/MacOS/project1
187187```
188188
189189## See also
190190
191191- [[Add an Apple Help Book to your macOS app]]
192192- [[Deploying Your Application|Deploying your macOS application]]
193193- [[Hiding a macOS app from the Dock]]
194194- [[macOS property list files]]
195195
196196## External links
197197
198198- [Apple: NSBundle class](https://developer.apple.com/documentation/foundation/nsbundle)
199199- [Apple: Bundle Resources](https://developer.apple.com/documentation/bundleresources/)
200200- [Apple: CFBundle](https://developer.apple.com/documentation/corefoundation/cfbundle)
201201- [Apple: Bundle Configuration](https://developer.apple.com/documentation/bundleresources/information_property_list/bundle_configuration)
202202- [Apple: Resource Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/LoadingResources/Introduction/Introduction.html)
203203- [Apple: Bundle Programming Guide](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html)
204204
205205---
206206*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