PAMGuard icon indicating copy to clipboard operation
PAMGuard copied to clipboard

Add ability to pass Java arguments to Pamguard.app on macOS

Open macster110 opened this issue 10 months ago • 0 comments

Using PAMGuard from another program e.g. MATLAB or the Batch Processor Module usually requires a number of arguments to be passed to the executable e.g. the location of the .psfx file or whether to run in viewer mode or not. This is easy in Windows but more complex in macOS.

Arguments are passed to .app file via the --args function, however, these are not passed through to the .jar file automatically e.g. open /Applications/Pamguard.app --args -v should open PAMGuard in viewer mode but does not.

The way to fix this is to modify executable script (see below) within Contents/MacOS directory. This will require significant modifications to the Maven build scripts but will then allow PAMGuard on MacOS to be called with custom arguments

#!/bin/bash

APP_HOME="$(dirname "$0")/.."
JAVA_HOME="$APP_HOME/PlugIns/jdk/Contents/Home" #Adjust path to your java runtime.
JAVA_EXECUTABLE="$JAVA_HOME/bin/java"
JAR_PATH="$APP_HOME/Java/YourApp.jar" #Adjust path to your jar file.

JVM_ARGS=""
APP_ARGS=""

# Parse arguments
while [[ $# -gt 0 ]]; do
    case "$1" in
        -X*) # JVM argument
            JVM_ARGS="$JVM_ARGS $1"
            shift
            ;;
        *) # Application argument
            APP_ARGS="$APP_ARGS $1"
            shift
            ;;
    esac
done

# Launch the Java application
"$JAVA_EXECUTABLE" $JVM_ARGS -jar "$JAR_PATH" $APP_ARGS

macster110 avatar Mar 17 '25 14:03 macster110