InstallerPane category to query the package path.
This should have been a public API in InstallerPane interface. Since it is not, here is the category to query the package path.
To use, add InstallerPane+VHInstallerPaneMissingMethodAdditions.h and InstallerPane+VHInstallerPaneMissingMethodAdditions.m files to your Installer plug-in project.
This will add 2 new methods to the InstallerPane class:
@interface InstallerPane (VHInstallerPaneMissingMethodAdditions)
- (NSString *)packagePath;
- (NSURL *)packageURL;
@end
and in your InstallerPane subclass file import the header file:
#import "InstallerPane+VHInstallerPaneMissingMethodAdditions.h"
The sample InstallerPluginTest project and InstallerPluginTest package demonstrate the usage. Works on macOS 10.15 Catalina and previous versions as well.
There a catch though:
On macOS 10.14 or earlier, the package path is queried from the Installer window that is hosting our InstallerPane, so the content view of the InstallerPane should be already added to the window. On macOS 10.15 Catalina, Installer plug-ins are instantiated in the separate process, so the caller need to wait for the response from the main Installer process. This means that the first call to packagePath/packageURL will initiate the query, but will return an empty path until the Installer process responds with the answer.
For that reason, packagePath and packageURL properties are KVO compliant on macOS 10.15 Catalina!
- (void)willEnterPane:(InstallerSectionDirection)dir
{
// the call will not succeed on Catalina because of request roundtrip to another process
// and on previous versions, because plug-in view is not yet added to the Installer window
NSLog(@"****** ---%@", self.packagePath);
}
- (void)didEnterPane:(InstallerSectionDirection)dir
{
// this call will succeed, because the plug-in view already added to the Installer window
NSLog(@"****** +++%@", self.packagePath);
}
Discovered that PACKAGE_PATH is not available for the scripts running in the installer requirements validation phase. This code snippet will get it for you...
if [[ "${PACKAGE_PATH}" == "" ]]; then
PROCESS_PATH=`ps -p $PPID -o comm=`
if [[ "${PROCESS_PATH}" == */Installer.app/Contents/MacOS/Installer ]];
then
PACKAGE_PATH=`sed -n -e "s/^.*Installer\[${PPID}\]: Opened from: //p" /var/log/install.log | tail -n1`
else
PACKAGE_PATH=`lsof -Fn -p $PPID | grep "n.*[.]pkg" | tail -n1 | cut -b 2-`
fi
fi