Save Installer From Mac App Store (Updates and New Apps)

If you are an OS X administrator and deploy apps or updates, having a .pkg format is very useful.  Wouldn’t it be nice to save the installer from the App Store?

By default, any new apps or updates magically appear in the /Applications  folder.  In the background, however, there is actually a .pkg being run by Installer.  There is a manual way to capture and save the .pkgs from the App Store, but I wanted to write  script that would do this automatically.

I was able to automate a big chunk of it.  You will still need to open the App Store and pause any downloads you want to save.  But once you do that, just run the script and it will save each .pkg to your downloads folder with a name like _MAS_1.pkg, _MAS_2.pkg, etc.

You can view the full source code on Github, but the gist of it, is below.