Make Anything Into an App on macOS

From girlwiki
Revision as of 21:10, 16 April 2023 by Flurry (talk | contribs) (Created page with "If you've used macOS/MacOSX and never poked around the structure of an App, I have some mind-blowing information for you: it's just a folder. A folder with more folders, in fact! == How macOS Apps Work == The basic structure of a macOS app is a-like so: <syntaxhighlight lang="text"> - MyCool.app/ + Contents/ + Info.plist + MacOS/ + CoolApp + Resources/ + AppIcon.icns + SomeOtherJunk.txt </syntaxhighlight> This isn't just specific to a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If you've used macOS/MacOSX and never poked around the structure of an App, I have some mind-blowing information for you: it's just a folder. A folder with more folders, in fact!

How macOS Apps Work

The basic structure of a macOS app is a-like so:

- MyCool.app/
  + Contents/
    + Info.plist
    + MacOS/
      + CoolApp
    + Resources/
      + AppIcon.icns
      + SomeOtherJunk.txt

This isn't just specific to applications! Kernel extensions, some plugins, and frameworks also follow this "actually a directory" format. These are called Bundles.[1]

Components of an App Bundle

Info.plist

The core component to a bundle is its Info.plist. All usable keys are provided in Apple Developer docs[2], but these should get you started:

<?xml version="1.0" encoding="UTF-8">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleIdentifier</key>
    <string>xyz.datagirl.cool-app</string>
    <!-- arbitrary, set by Xcode. prolly don't change it -->
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <!--
         This can only be up to 15 characters! Use CFBundleDisplayName if you
         need a longer version for Siri and the sort.
      -->
    <key>CFBundleName</key>
    <string>CoolApp</string>
    <key>CFBundleVersion</key>
    <string>1.0.69</string>
    <!-- relative to Resources/ -->
    <key>CFBundleIconFile</key>
    <string>AppIcon.icns</string>
    <key>CFBundleIconName</key>
    <string>AppIcon</string>
    <!-- relative to MacOS/. technically should be the same as your .app name -->
    <key>CFBundleExecutable</key>
    <string>CoolApp</string>
    <!-- APPL = we're an App -->
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <!-- Do we support Retina? (idk if this matters for our purposes) -->
    <key>NSHighResolutionCapable</key>
    <true/>
</dict>
</plist>

The program itself

Make a program named the same as what you set CFBundleExecutable to in your Info.plist. This can be a macOS binary, or interpreted code, such as a shell script. You'll need to make sure it's executable, of course. Save it to the Contents/MacOS directory in your app.

App Icon

Generating an ICNS file is an exercise left to the reader.[3] Once you have it, save it with the same name you set as CFBundleIconFile in the Contents/Resources directory in your app.

Notes

  1. About Bundles, from the Bundle Programming Guide by Apple.
  2. Bundle configuration, from Apple Developer Documentation.
  3. But this gist worked well for me.