Sign in Join
Wiki copytemporary

Creating an app bundle for GTK applications: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Creating an app bundle for GTK applications

OldNewLine
1+*(macOS only)*
2+
3+For macOS you need to create an app bundle for an executable file in order to drop it on the dock or launch it by double-clicking. An app bundle is really just a special folder that can have the same name as the executable, but with an .app extension. Finder doesn't display the .app extension, although you'll see it if you use ls in a Terminal window.
4+
5+The Carbon and Qt pages both explain how to create an app bundle for apps compiled with those widgetsets. With a GTK app, it's a bit more complicated since X11 always has to be running in order to run the app. Copy and paste the following script to a file named *create_gtk_app.sh*, use chmod +x on the file so macOS will let you run it, then run it as follows to create an app bundle (substitute the name of your own GUI app compiled with the GTK widgetset):
6+
7+``` bash
8+./create_gtk_app.sh execfile
9+```
10+
11+Now you can drag and drop the resulting app bundle onto the dock just like any other application.
12+
13+For more information, study the script.
14+
15+***Tip:*** In the script below, one of the lines is really long and may get chopped off when you print this page *(but why would you print this page only to type it in again when you can just copy and paste?) --BigChimp 12:37, 24 November 2013 (CET)*. Here's the line on two lines. Just be sure it's all one line in your script file.
16+
17+``` bash
18+ echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
19+ "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >>$plistfile
20+```
21+
22+``` bash
23+#!/bin/sh
24+# Force Bourne shell in case another shell is the default.
25+#
26+appname=$1
27+appfolder=$appname.app
28+macosfolder=$appfolder/Contents/MacOS
29+plistfile=$appfolder/Contents/Info.plist
30+if [ $appname = "lazarus" ]
31+then
32+ appfile=/usr/local/share/lazarus/lazarus
33+else
34+ appfile=$appname
35+fi
36+#
37+if [ "$appname" = "" ]
38+then
39+ echo "Usage: $0 executable_file"
40+ echo "Creates .app bundle (folder) for executable file that uses GTK widgetset"
41+elif ! [ -e $appfile ]
42+then
43+ echo "$appfile does not exist"
44+elif [ -e $appfolder ]
45+then
46+ echo "$appfolder already exists"
47+else
48+ echo "Creating $appfolder..."
49+ mkdir $appfolder
50+ mkdir $appfolder/Contents
51+ mkdir $appfolder/Contents/MacOS
52+ mkdir $appfolder/Contents/Resources
53+#
54+ if [ $appname = "lazarus" ]
55+ then
56+# This is special case for lazarus IDE.
57+# Create a script file in .app folder that starts X11, then Lazarus.
58+ echo '#!/bin/sh' >$macosfolder/$appname.sh
59+ echo '# This script starts X11, then Lazarus.' >>$macosfolder/$appname.sh
60+ echo 'open -a x11' >>$macosfolder/$appname.sh
61+ echo "export DISPLAY=':0.0'" >>$macosfolder/$appname.sh
62+ echo 'open -a '$appfile >>$macosfolder/$appname.sh #IMPORTANT! If you're running TCSH, or other,
63+ chmod +x $macosfolder/$appname.sh # "open -a" doesn't work. Use "open" instead
64+ else
65+# Instead of copying executable into .app folder after each compile,
66+# simply create a symbolic link to executable.
67+ ln -s ../../../$appname $macosfolder/$appname
68+# Create a little script file in .app folder that opens executable with X11.
69+ echo '#!/bin/sh' >$macosfolder/$appname.sh
70+ echo '# This script opens the executable file with X11.' >>$macosfolder/$appname.sh
71+ echo 'open ${0/%.sh}' >>$macosfolder/$appname.sh
72+ chmod +x $macosfolder/$appname.sh
73+ fi
74+#
75+# Create PkgInfo file.
76+ echo "APPL????" >$appfolder/Contents/PkgInfo
77+#
78+# Create information property list file (Info.plist).
79+ echo '<?xml version="1.0" encoding="UTF-8"?>' >$plistfile
80+ echo '<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >>$plistfile
81+ echo '<plist version="1.0">' >>$plistfile
82+ echo '<dict>' >>$plistfile
83+ echo ' <key>CFBundleDevelopmentRegion</key>' >>$plistfile
84+ echo ' <string>English</string>' >>$plistfile
85+ echo ' <key>CFBundleExecutable</key>' >>$plistfile
86+ echo ' <string>'$appname'.sh</string>' >>$plistfile
87+ echo ' <key>CFBundleInfoDictionaryVersion</key>' >>$plistfile
88+ echo ' <string>6.0</string>' >>$plistfile
89+ echo ' <key>CFBundlePackageType</key>' >>$plistfile
90+ echo ' <string>APPL</string>' >>$plistfile
91+ echo ' <key>CFBundleSignature</key>' >>$plistfile
92+ echo ' <string>????</string>' >>$plistfile
93+ echo ' <key>CFBundleVersion</key>' >>$plistfile
94+ echo ' <string>1.0</string>' >>$plistfile
95+ echo ' <key>CSResourcesFileMapped</key>' >>$plistfile
96+ echo ' <true/>' >>$plistfile
97+ echo '</dict>' >>$plistfile
98+ echo '</plist>' >>$plistfile
99+fi
100+```
101+
102+---
103+*From the Free Pascal wiki, page "Creating an app bundle for GTK applications", as it stood on 2019-12-14 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).*
104+Category: Code Snippets
105+Category: GTK Widgetsets
106+Category: macOS

Back to history