The main metadata file for macOS applications is called Info.plist and, like the desktop entry for Linux, it is a structured text file. For a Go project, it is best to edit the text directly rather than using the installed Xcode tools. This file contains a list of key-value pairs that describe the application we've built. It's important that you do not change the values for CFBundlePackageType or CFBundleInfoDictionaryVersion as these identify the file to macOS as an application.
The main keys for customization are CFBundleExecutable, which sets the name of the executable file; CFBundleName, for the human-visible name of the application; and CFBundleIconFile, to specify the icon filename. It's important to set sensible values for CFBundleIdentifier as this uniquely identifies this application, and CFBundleShortVersionString, which specifies what version of the application is included. Putting all of these values into the plist format, you should have a file similar to the following:
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>myapp</string>
<key>CFBundleIdentifier</key>
<string>com.example.myapp</string>
<key>CFBundleName</key>
<string>MyApp</string>
<key>CFBundleIconFile</key>
<string>myapp.icns</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
One additional step when creating a macOS package is that the icon must be in the ICNS format. ICNS files contain many different sized icons so that macOS can display a clear graphic at various resolutions. There are many graphical tools to manipulate these files (search create icns file online), but the XCode command-line tools include iconutil, a simple utility that can create these files from a set of icons.
When invoking iconutil, we specify that it should convert to icns with the -c icns parameter, and provide the output file name using -o <filename>. The last parameter is the iconset input—a directory of appropriately named files that will be included. For our 1024 x 1024 pixels icon, we call it [email protected], but it is recommended to provide multiple different resolutions. Running the command will create the .icns file we need for our application icon, as follows:
iconutil -c icns -o Chapter14.app/Contents/Resources/chapter14.icns chapter14.iconset/