private <T> T loadAskValue(T defaultValue, StringTransformer<T> transformer, String key) {

		boolean isHeadless = isRunningHeadless();
		if (isHeadless && scriptArgs.length > 0) {
			// this will throw IllegalArgumenrException if the args cannot be parsed
			return transformer.apply(nextScriptArg());
		}

		boolean hasDefault = !isBlank(defaultValue);

		String propertyKey = key;
		if (propertiesFileParams == null) {

			if (isHeadless && !hasDefault) { // require either a props file or a default value
				throw new IllegalArgumentException("Error processing variable '" + propertyKey +
					"' in headless mode -- it was not found in script arguments or a .properties file.");
			}
			return defaultValue; // may be null
		}

		String storedValue = propertiesFileParams.getValue(propertyKey);
		if (storedValue.isEmpty()) {

			if (isHeadless && !hasDefault) { // require either a props file or a default value
				throw new IllegalArgumentException("Error processing variable '" + propertyKey +
					"' in headless mode -- it was not found in script arguments or a .properties file.");
			}
			return defaultValue;
		}

		try {
			T t = transformer.apply(storedValue);
			return t;
		}
		catch (IllegalArgumentException e) {
			// handled below
		}

		if (isHeadless) {
			throw new IllegalArgumentException("Error processing variable '" + propertyKey +
				"' in headless mode -- its value '" + storedValue + "' is not a valid value.");
		}

		Msg.warn(this, "Failed to parse script properties value '" + key + "' from file " +
			propertiesFileParams.getFilename());
		return null;
	}
This version of {@link #loadAskValue(StringTransformer, String)} will use
the given default, if not null and not empty, instead of failing when a value is not
provided by the client when in headless.

@param defaultValue an optional default value that will be used if no suitable
                    value can be found in script args or a properties file
@param transformer the function to turn a String into a T
@param key the value property key used for lookup in the script properties file
@return null if no value was found in the aforementioned sources

@throws IllegalArgumentException if the loaded String value cannot be parsed into a
                                 <code>T</code> or property not defined when in headless
                                 mode and no defaultValue has been specified.
Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScript.java