Here's a way to build your Godot 4 game automatically from macOS terminal.
#!/bin/bash
# Constants
PROJECT_PATH="$(pwd)"
EXPORT_PRESET="Windows Desktop"
OUTPUT_DIR="./Builds"
LOG_FILE="$OUTPUT_DIR/export_log.txt"
GODOT_PATH="/Applications/Godot.app/Contents/MacOS/Godot"
# Function to log messages
log_message() {
echo "$(date): $1" | tee -a "$LOG_FILE"
}
# Clear previous log
echo "" > "$LOG_FILE"
# Ensure we're in a Godot project directory
if [ ! -f "project.godot" ]; then
log_message "Error: project.godot not found in the current directory. Please run this script from your Godot project root."
exit 1
fi
# Ensure output directory exists
mkdir -p "$OUTPUT_DIR"
# Check if Godot is available
if [ ! -f "$GODOT_PATH" ]; then
log_message "Error: Godot executable not found. Please ensure Godot is installed in the Applications folder."
exit 1
fi
# Log the Godot version
GODOT_VERSION=$("$GODOT_PATH" --headless --version 2>&1 | tail -n 1)
log_message "Using Godot version: $GODOT_VERSION"
# Generate timestamp for the filename
TIMESTAMP=$(date +"%Y%m%d-%H%M")
OUTPUT_FILE="MyGame-alpha-$TIMESTAMP.exe"
# Export the project
log_message "Starting export process..."
"$GODOT_PATH" --headless --path "$PROJECT_PATH" --export-release "$EXPORT_PRESET" "$OUTPUT_DIR/$OUTPUT_FILE" 2>&1 | tee -a "$LOG_FILE"
# Check if export was successful
if [ -f "$OUTPUT_DIR/$OUTPUT_FILE" ]; then
log_message "Export successful. File saved as $OUTPUT_DIR/$OUTPUT_FILE"
else
log_message "Export failed. Check the log file for details."
exit 1
fi
log_message "Export and copy process completed successfully."
copy this as ./autobuild
into your project root
run chmod +x ./autobuild
in Mac Terminal to give it the ability to run
run ./autobuild
anytime you want to make a build in your Builds folder.
you could pair it with something like watchman to run it automatically on save.