create-emacsclient-app-macos.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/bin/bash
  2. # Create Emacsclient.app for macOS
  3. # This script creates a proper .app bundle that uses emacsclient
  4. APP_NAME="Emacsclient"
  5. APP_DIR="/Applications/${APP_NAME}.app"
  6. CONTENTS_DIR="${APP_DIR}/Contents"
  7. MACOS_DIR="${CONTENTS_DIR}/MacOS"
  8. RESOURCES_DIR="${CONTENTS_DIR}/Resources"
  9. # Adjust these paths based on your system
  10. EMACS_BIN="/usr/local/bin/emacs"
  11. EMACSCLIENT_BIN="/usr/local/bin/emacsclient"
  12. # For Apple Silicon Macs with Homebrew, use:
  13. # EMACS_BIN="/opt/homebrew/bin/emacs"
  14. # EMACSCLIENT_BIN="/opt/homebrew/bin/emacsclient"
  15. echo "Creating ${APP_NAME}.app..."
  16. # Create directory structure
  17. mkdir -p "${MACOS_DIR}"
  18. mkdir -p "${RESOURCES_DIR}"
  19. # Create the launcher script
  20. cat > "${MACOS_DIR}/${APP_NAME}" << EOF
  21. #!/bin/bash
  22. # Check if Emacs server is running
  23. if ! ${EMACSCLIENT_BIN} -e "(boundp 'server-process)" 2>/dev/null | grep -q "t"; then
  24. # Start Emacs daemon if not running
  25. ${EMACS_BIN} --daemon
  26. # Wait a moment for daemon to start
  27. sleep 1
  28. fi
  29. # Open emacsclient with a new frame
  30. # -c creates a new frame
  31. # -n returns immediately without waiting
  32. exec ${EMACSCLIENT_BIN} -c -n "\$@"
  33. EOF
  34. # Make the launcher executable
  35. chmod +x "${MACOS_DIR}/${APP_NAME}"
  36. # Create Info.plist
  37. cat > "${CONTENTS_DIR}/Info.plist" << 'EOF'
  38. <?xml version="1.0" encoding="UTF-8"?>
  39. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  40. <plist version="1.0">
  41. <dict>
  42. <key>CFBundleExecutable</key>
  43. <string>Emacsclient</string>
  44. <key>CFBundleIconFile</key>
  45. <string>Emacs.icns</string>
  46. <key>CFBundleIdentifier</key>
  47. <string>org.gnu.Emacsclient</string>
  48. <key>CFBundleName</key>
  49. <string>Emacsclient</string>
  50. <key>CFBundlePackageType</key>
  51. <string>APPL</string>
  52. <key>CFBundleShortVersionString</key>
  53. <string>1.0</string>
  54. <key>CFBundleVersion</key>
  55. <string>1.0</string>
  56. <key>LSMinimumSystemVersion</key>
  57. <string>10.10</string>
  58. <key>NSHighResolutionCapable</key>
  59. <true/>
  60. <key>CFBundleDocumentTypes</key>
  61. <array>
  62. <dict>
  63. <key>CFBundleTypeExtensions</key>
  64. <array>
  65. <string>*</string>
  66. </array>
  67. <key>CFBundleTypeName</key>
  68. <string>All Files</string>
  69. <key>CFBundleTypeRole</key>
  70. <string>Editor</string>
  71. </dict>
  72. </array>
  73. </dict>
  74. </plist>
  75. EOF
  76. # Copy icon from existing Emacs.app if available
  77. if [ -f "/Applications/Emacs.app/Contents/Resources/Emacs.icns" ]; then
  78. cp "/Applications/Emacs.app/Contents/Resources/Emacs.icns" "${RESOURCES_DIR}/"
  79. echo "Icon copied from Emacs.app"
  80. elif [ -f "/opt/homebrew/Caskroom/emacs/*/Emacs.app/Contents/Resources/Emacs.icns" ]; then
  81. cp /opt/homebrew/Caskroom/emacs/*/Emacs.app/Contents/Resources/Emacs.icns "${RESOURCES_DIR}/"
  82. echo "Icon copied from Homebrew Emacs.app"
  83. else
  84. echo "Warning: Could not find Emacs.icns icon file"
  85. fi
  86. echo "Successfully created ${APP_DIR}"
  87. echo ""
  88. echo "You can now:"
  89. echo "1. Double-click Emacsclient in /Applications to launch"
  90. echo "2. Add it to your Dock"
  91. echo "3. Set it as default handler for text files"
  92. echo "4. Open files with: open -a Emacsclient file.txt"