#!/bin/bash # Create Emacsclient.app for macOS # This script creates a proper .app bundle that uses emacsclient APP_NAME="Emacsclient" APP_DIR="/Applications/${APP_NAME}.app" CONTENTS_DIR="${APP_DIR}/Contents" MACOS_DIR="${CONTENTS_DIR}/MacOS" RESOURCES_DIR="${CONTENTS_DIR}/Resources" # Adjust these paths based on your system EMACS_BIN="/usr/local/bin/emacs" EMACSCLIENT_BIN="/usr/local/bin/emacsclient" # For Apple Silicon Macs with Homebrew, use: # EMACS_BIN="/opt/homebrew/bin/emacs" # EMACSCLIENT_BIN="/opt/homebrew/bin/emacsclient" echo "Creating ${APP_NAME}.app..." # Create directory structure mkdir -p "${MACOS_DIR}" mkdir -p "${RESOURCES_DIR}" # Create the launcher script cat > "${MACOS_DIR}/${APP_NAME}" << EOF #!/bin/bash # Check if Emacs server is running if ! ${EMACSCLIENT_BIN} -e "(boundp 'server-process)" 2>/dev/null | grep -q "t"; then # Start Emacs daemon if not running ${EMACS_BIN} --daemon # Wait a moment for daemon to start sleep 1 fi # Open emacsclient with a new frame # -c creates a new frame # -n returns immediately without waiting exec ${EMACSCLIENT_BIN} -c -n "\$@" EOF # Make the launcher executable chmod +x "${MACOS_DIR}/${APP_NAME}" # Create Info.plist cat > "${CONTENTS_DIR}/Info.plist" << 'EOF' CFBundleExecutable Emacsclient CFBundleIconFile Emacs.icns CFBundleIdentifier org.gnu.Emacsclient CFBundleName Emacsclient CFBundlePackageType APPL CFBundleShortVersionString 1.0 CFBundleVersion 1.0 LSMinimumSystemVersion 10.10 NSHighResolutionCapable CFBundleDocumentTypes CFBundleTypeExtensions * CFBundleTypeName All Files CFBundleTypeRole Editor EOF # Copy icon from existing Emacs.app if available if [ -f "/Applications/Emacs.app/Contents/Resources/Emacs.icns" ]; then cp "/Applications/Emacs.app/Contents/Resources/Emacs.icns" "${RESOURCES_DIR}/" echo "Icon copied from Emacs.app" elif [ -f "/opt/homebrew/Caskroom/emacs/*/Emacs.app/Contents/Resources/Emacs.icns" ]; then cp /opt/homebrew/Caskroom/emacs/*/Emacs.app/Contents/Resources/Emacs.icns "${RESOURCES_DIR}/" echo "Icon copied from Homebrew Emacs.app" else echo "Warning: Could not find Emacs.icns icon file" fi echo "Successfully created ${APP_DIR}" echo "" echo "You can now:" echo "1. Double-click Emacsclient in /Applications to launch" echo "2. Add it to your Dock" echo "3. Set it as default handler for text files" echo "4. Open files with: open -a Emacsclient file.txt"