Package Mac Command Line As App

In this how-to I'll show you how to launch an OS X app from the command line with the open command. Note: A little bit of prior UNIX experience will be helpful here. First off, I will admit this. Jul 11, 2020  A few posts back, I talked about the script I use to package macOS apps that I distribute outside of the Mac App Store. That script is designed to simplify the complex process of signing and notarizing not only the app itself but also the installer package its. Jul 21, 2005  installation of Mac OS X packages via the command line. 1) Download the Package Download the installation image to a local directory. I usually download packages to the admin/staging directory a client convention. Don't try to download it to some target directory like /etc or /usr I use 'curl' to fetch the package from the net. Sep 26, 2011  In such a situation, you can then turn to the command line to extract a package file. How to Expand a Package File on Mac by Command Line. Assuming the ‘Show Package Contents’ option is unavailable, we can extract.pkg files using a command line tool called pkgutil that is bundled with Mac OS, which is what we’re going to focus on here. I sometimes need to install updates remotely on a server I maintain. I already knew about the command line version of softwareupdate, but I was looking for a way to install packages (.pkg) that were already located on the remote box. I finally found the installer command. To install a package, type: sudo installer -pkg Desktop/Java1.4.1.pkg. Installing applications on macOS and OS X computers is easy to do when deploying the apps as packages through the Terminal using the Installer command for quiet deployments across your network.

In some flavors of Unix, you feel as if you've been cast into an alternate universe when you open a terminal window and work on the command line. But with OS X and its Darwin core, there's often an elegant integration between the two. In this how-to I'll show you how to launch an OS X app from the command line with the open command.

[Note: A little bit of prior UNIX experience will be helpful here.]

First off, I will admit this technique is fairly geeky. In my [Mac] OS X career, I've only used this trick a handful of times. However, it's so darn cool and charming that one just aches to use it at any opportunity.

Actually, upon reflection, there are some useful scenarios for this technique.

  1. The Finder acts up, a terminal window is already open, and you'd like to be able to launch a GUI app that might help you diagnose the problem.
  2. You're a UNIX professional, live and breathe the command line, but you'd rather use a GUI text editor for coding instead of the raw and ugly vi or Emacs editors.
  3. You're writing, say, a Perl or Python script, for another user and, at some point in the script, you'd like to launch a GUI app that carries the workflow forward.
  4. You want to quickly run a utility with admin privileges without the restriction of the account you're logged into. See, for example, 'How to Find & Recover Missing Hard Drive Space.' In that case, you must bypass the open command and drill into the Package Contents to run the app with sudo and admin privileges. But I've digressed.

The Man Page

The terminal app is in the Utilities folder—which is found the Applications folder. Launch it now. The BSD UNIX command we'll be using is open. Below is the manual page ('man' for short), shown by typing:

I've printed most of the man page for the open command here for your perusal, but I'm not going to explore every argument. And feel free to jump right to the examples below to whet your appetite.

For this limited how-to, one interesting way to use the open command in this context is to use the [-a] option. Some other useful variations and arguments are in the examples below.

Typical Examples

Here are some short and sweet examples of the open command with the -a, -e, and -t arguments. They're easy to try. [If you don't have BBEdit installed, use any other favorite a text editor in /Applications.]

Open Doors

These are just a few of the cool things you can do on the command line with the open command. To keep things simple, I haven't delved into creating a search path or other Unix tricks like aliases. All that's been left for you to explore on your own.

I think this is one of the neatest tricks in OS X.

__________________

Launch button via Shutterstock.

If you happen to be faced with a package (.pkg) or meta-package (.mpkg) file and want to inspect its contents before you initiate an install, there's a nifty OS X utility that can dump out the files contained inside for your inspection.

_____________________

Application Packages

Package Mac Command Line As Application

First, I need to backtrack for a minute.

As OS X users, we're familiar with the fact that applications are actually complex folders in disguise—packages in developer lingo. OS X recognizes application packages and knows how to give them their unique icon. There is a contextual menu item, 'Show Package Contents' that allows one to drill into the guts of an application and view all its resources.

Sow Package Contents on an app.
Right click for contextual menu.

Inspecting Installer Packages

Package Mac Command Line As Apply

One might think, at first, that the OS X command 'Show Package Contents' will work on another package file, an installer that ends in .pkg or .mpkg. That may or may not work depending on how the package file is constructed.

Note that .mpkg files are meta-packages that may contain .pkg files inside them that may be amendable to Show Package Contents.

However, if Show Package Contents isn't provided as a contextual menu option for either type of installer, don't despair. A different kind of tool is needed to analyze it. In this case, one can use a nifty OS X command line tool called pkgutil. It extracts the contents of the package file into its component pieces and can write it all out to a folder for inspection.

The easiest way to get started is to do a simple expand option and write it out to a named folder. The 'man' page, of course, shows all the options. In the simplest case, the terminal commands would be:

In these examples, the destination folder will be in the same folder as the package file, but one could define a path to somewhere else.

Here's what a dump looks like for one of my .mpkg files.

Sample dump of a .mpkg file.

In researching this command, I discovered a nice GUI utility called Pacifist (OS X 10.8 or later) that can drill into, amongst others, .dmg and .pkg files. It's $20 shareware, and if one works in the above mode a lot, it could well be worth the investment. But for casual inspection, the pkgutil command is nice to know about.