Skip to content

Instantly share code, notes, and snippets.

@sirj0k3r
Last active August 29, 2025 11:15
Show Gist options
  • Select an option

  • Save sirj0k3r/175fe07fa71e5c2fa53f1bb55ff191f5 to your computer and use it in GitHub Desktop.

Select an option

Save sirj0k3r/175fe07fa71e5c2fa53f1bb55ff191f5 to your computer and use it in GitHub Desktop.
Creating a PKHeX.app using Wine
#!/bin/bash
DIR=$(dirname $0 | realpath)
# Check for .NET
if command -v dotnet >/dev/null 2>&1; then
echo "Skipping .NET installation"
else
echo ".NET is not installed. Installing..."
/bin/bash -c "$(curl -fsSL https://dot.net/v1/dotnet-install.sh)"
fi
# Check for Homebrew and install if missing
if command -v brew >/dev/null 2>&1; then
echo "Skipping Homebrew installation."
else
echo "Homebrew is not installed. Installing..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
# Check for Wine and install if missing
if command -v wine >/dev/null 2>&1; then
echo "Skipping Wine installation."
WINE=$(which wine)
else
echo "Wine is not installed. Installing using brew..."
brew install wine@staging
fi
# Download PKHeX project
git clone https://github.com/kwsch/PKHeX.git "PKHeX-master"
# Get current version
VER=$(xmllint --xpath '//Project/PropertyGroup/Version/text()' PKHeX-master/Directory.Build.props)
# Publish the binaries as self-contained
echo "Publishing PKHeX as a self contained app"
dotnet publish "$DIR/PKHeX-master/PKHeX.WinForms" -c Release --self-contained true -o "$DIR/PKHeX.pub"
# Create PKHeX.app
echo "Creating PKHeX.app"
mkdir "$DIR/PKHeX.app" "$DIR/PKHeX.app/Contents" "$DIR/PKHeX.app/Contents/MacOS" "$DIR/PKHeX.app/Contents/Resources" "$DIR/PKHeX.app/Contents/Resources/bak"
echo "Creating base files for PKHeX.app"
# Write the Info.plist
cat > "$DIR/PKHeX.app/Contents/Info.plist" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key>
<string>PKHeX</string>
<key>CFBundleDisplayName</key>
<string>PKHeX</string>
<key>CFBundleIdentifier</key>
<string>com.sirj0k3r.pkhex</string>
<key>CFBundleVersion</key>
<string>$VER</string>
<key>CFBundleExecutable</key>
<string>PKHeX</string>
<key>CFBundleIconFile</key>
<string>PKHeX</string>
<key>LSMinimumSystemVersion</key>
<string>10.12.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
</dict>
</plist>
EOF
# Copy PKHeX to the App
echo "Copying PKHeX.exe to PKHeX.app"
cp "$DIR/PKHeX.pub/PKHeX.exe" "$DIR/PKHeX.app/Contents/Resources"
# Write the launch script
echo "Creating launch script"
cat > "$DIR/PKHeX.app/Contents/MacOS/PKHeX" << 'EOF'
#!/bin/bash
DIR="$(cd "$(dirname "$0")/../Resources" && pwd)"
EXE="$DIR/PKHeX.exe"
WINE="/opt/homebrew/bin/wine"
WINEPREFIX="$HOME/.wine32"
export WINEPREFIX
#export WINEARCH="win32"
# Initialize Wine prefix if it doesn't exist
if [ ! -d "$WINEPREFIX" ]; then
"$WINE wineboot"
fi
# Run the exe
wine "$EXE"
EOF
# Give permissions to launch script
chmod +x "$DIR/PKHeX.app/Contents/MacOS/PKHeX"
if [ "$1" == "--no-clean" ]; then
echo "Done!"
exit 1
fi
# Cleaning up
echo "Cleaning up..."
rm -rf PKHeX-master PKHeX.pub
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment