Application Bundle

From Lazarus wiki
Jump to: navigation, search

English (en) | 日本語 (ja)

Application Bundle is a directory, often with ".app" extension, with special purpose on Mac OS X system. It contains resource files and information about the application. It is necessary for correct execution of applications which are using Carbon Interface.


Contents

Overview

You can learn more about application bundles at the developer.apple.com.

Application (bundle) settings are located in property list file: Info.plist located in the bundle.app/Contents/ directory.

To access it, you need to right click (ctrl-left click) on a bundle and select Show Package Contents

openbundle.png

infoplist.png

You can learn about possible properties here

Creating Application Bundle

From Lazarus

Open project and go to Project -> Project Options -> Application tab and push the Create Application Bundle button. The resulted Application Bundle will have inside symbolic link to the real executable.

Via command-line tool shipped with Lazarus

Open lazarus/components/macfiles/examples/createmacapplication.lpi in the IDE. Compile. Open a Terminal of your choice. Type:

cd project1/
lazarus/components/macfiles/examples/createmacapplication project1
ln -s ../../../project1 project1.app/Contents/MacOS/project1

Use shell script

You can adapt the following shell script to create a customized application bundle for your application. It allows the creation of either debug or release bundle.

  • In the debug bundle, a link to the executable is placed, allowing for debugging using the Lazarus IDE,
  • In the release bundle, the executable is copied so the application bundle as a whole can be used stand-alone/copied to other locations.
#!/bin/sh
# Force Bourne shell in case tcsh is default.
#
 
#
# Reads the bundle type
#
 
echo "========================================================"
echo "    Bundle creation script"
echo "========================================================"
echo ""
echo " Please select which kind of bundle you would like to build:"
echo ""
echo " 1 > Debug bundle"
echo " 2 > Release bundle"
echo " 0 > Exit"
 
read command
 
case $command in
 
  1) ;;
 
  2) ;;
 
  0) exit 0;;
 
  *) echo "Invalid command"
     exit 0;;
 
esac
 
#
# Creates the bundle
#
 
appname=Magnifier
appfolder=$appname.app
macosfolder=$appfolder/Contents/MacOS
plistfile=$appfolder/Contents/Info.plist
appfile=magnifier
 
PkgInfoContents="APPLMAG#"
 
#
if ! [ -e $appfile ]
then
  echo "$appfile does not exist"
elif [ -e $appfolder ]
then
  echo "$appfolder already exists"
else
  echo "Creating $appfolder..."
  mkdir $appfolder
  mkdir $appfolder/Contents
  mkdir $appfolder/Contents/MacOS
  mkdir $appfolder/Contents/Resources
 
#
# For a debug bundle,
# Instead of copying executable into .app folder after each compile,
# simply create a symbolic link to executable.
#
if [ $command = 1 ]; then
  ln -s ../../../$appname $macosfolder/$appname
else
  cp $appname $macosfolder/$appname
fi  
 
# Copy the resource files to the correct place
  cp *.bmp $appfolder/Contents/Resources
  cp icon3.ico $appfolder/Contents/Resources
  cp icon3.png $appfolder/Contents/Resources
  cp macicon.icns $appfolder/Contents/Resources
  cp docs/*.* $appfolder/Contents/Resources
#
# Create PkgInfo file.
  echo $PkgInfoContents >$appfolder/Contents/PkgInfo
#
# Create information property list file (Info.plist).
  echo '<?xml version="1.0" encoding="UTF-8"?>' >$plistfile
  echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >>$plistfile
  echo '<plist version="1.0">' >>$plistfile
  echo '<dict>' >>$plistfile
  echo '  <key>CFBundleDevelopmentRegion</key>' >>$plistfile
  echo '  <string>English</string>' >>$plistfile
  echo '  <key>CFBundleExecutable</key>' >>$plistfile
  echo '  <string>'$appname'</string>' >>$plistfile
  echo '  <key>CFBundleIconFile</key>' >>$plistfile
  echo '  <string>macicon.icns</string>' >>$plistfile
  echo '  <key>CFBundleIdentifier</key>' >>$plistfile
  echo '  <string>org.magnifier.magnifier</string>' >>$plistfile
  echo '  <key>CFBundleInfoDictionaryVersion</key>' >>$plistfile
  echo '  <string>6.0</string>' >>$plistfile
  echo '  <key>CFBundlePackageType</key>' >>$plistfile
  echo '  <string>APPL</string>' >>$plistfile
  echo '  <key>CFBundleSignature</key>' >>$plistfile
  echo '  <string>MAG#</string>' >>$plistfile
  echo '  <key>CFBundleVersion</key>' >>$plistfile
  echo '  <string>1.0</string>' >>$plistfile
  echo '</dict>' >>$plistfile
  echo '</plist>' >>$plistfile
fi

Executing application via Application Bundle

You can start the application from IDE (checked option Use Application Bundle for running and debugging (darwin only)) or via its Finder icon or in the native Mac OS X Terminal via "open project1.app".

Personal tools