diff --git a/Formula/emacs-plus@28.rb b/Formula/emacs-plus@28.rb index 1617a86f..fd08db43 100644 --- a/Formula/emacs-plus@28.rb +++ b/Formula/emacs-plus@28.rb @@ -260,7 +260,11 @@ def caveats To link the application to default Homebrew App location: osascript -e 'tell application "Finder" to make alias file to posix file "#{prefix}/Emacs.app" at posix file "/Applications" with properties {name:"Emacs.app"}' - Your PATH value was injected into Emacs.app/Contents/Info.plist + Your PATH value was injected into Emacs.app via a wrapper script. + This solves the issue with macOS Sequoia ignoring LSEnvironment in Info.plist. + + To disable PATH injection, set EMACS_PLUS_NO_PATH_INJECTION before running Emacs: + export EMACS_PLUS_NO_PATH_INJECTION=1 Report any issues to https://github.com/d12frosted/homebrew-emacs-plus EOS diff --git a/Formula/emacs-plus@29.rb b/Formula/emacs-plus@29.rb index 856cf3fd..2e5eef72 100644 --- a/Formula/emacs-plus@29.rb +++ b/Formula/emacs-plus@29.rb @@ -274,7 +274,11 @@ def caveats To link the application to default Homebrew App location: osascript -e 'tell application "Finder" to make alias file to posix file "#{prefix}/Emacs.app" at posix file "/Applications" with properties {name:"Emacs.app"}' - Your PATH value was injected into Emacs.app/Contents/Info.plist + Your PATH value was injected into Emacs.app via a wrapper script. + This solves the issue with macOS Sequoia ignoring LSEnvironment in Info.plist. + + To disable PATH injection, set EMACS_PLUS_NO_PATH_INJECTION before running Emacs: + export EMACS_PLUS_NO_PATH_INJECTION=1 Report any issues to https://github.com/d12frosted/homebrew-emacs-plus EOS diff --git a/Formula/emacs-plus@30.rb b/Formula/emacs-plus@30.rb index 8fb43ef9..50af7ac0 100644 --- a/Formula/emacs-plus@30.rb +++ b/Formula/emacs-plus@30.rb @@ -277,7 +277,11 @@ def caveats To link the application to default Homebrew App location: osascript -e 'tell application "Finder" to make alias file to posix file "#{prefix}/Emacs.app" at posix file "/Applications" with properties {name:"Emacs.app"}' - Your PATH value was injected into Emacs.app/Contents/Info.plist + Your PATH value was injected into Emacs.app via a wrapper script. + This solves the issue with macOS Sequoia ignoring LSEnvironment in Info.plist. + + To disable PATH injection, set EMACS_PLUS_NO_PATH_INJECTION before running Emacs: + export EMACS_PLUS_NO_PATH_INJECTION=1 Report any issues to https://github.com/d12frosted/homebrew-emacs-plus EOS diff --git a/Formula/emacs-plus@31.rb b/Formula/emacs-plus@31.rb index 3d022963..eb25d877 100644 --- a/Formula/emacs-plus@31.rb +++ b/Formula/emacs-plus@31.rb @@ -256,7 +256,11 @@ def caveats To link the application to default Homebrew App location: osascript -e 'tell application "Finder" to make alias file to posix file "#{prefix}/Emacs.app" at posix file "/Applications" with properties {name:"Emacs.app"}' - Your PATH value was injected into Emacs.app/Contents/Info.plist + Your PATH value was injected into Emacs.app via a wrapper script. + This solves the issue with macOS Sequoia ignoring LSEnvironment in Info.plist. + + To disable PATH injection, set EMACS_PLUS_NO_PATH_INJECTION before running Emacs: + export EMACS_PLUS_NO_PATH_INJECTION=1 Report any issues to https://github.com/d12frosted/homebrew-emacs-plus EOS diff --git a/Library/EmacsBase.rb b/Library/EmacsBase.rb index a29f7c1b..72a3b185 100644 --- a/Library/EmacsBase.rb +++ b/Library/EmacsBase.rb @@ -31,20 +31,37 @@ def self.inject_icon_options end def inject_path - ohai "Injecting PATH value to Emacs.app/Contents/Info.plist" + ohai "Injecting PATH via wrapper script in Emacs.app/Contents/MacOS/Emacs" app = "#{prefix}/Emacs.app" - plist = "#{app}/Contents/Info.plist" + emacs_binary = "#{app}/Contents/MacOS/Emacs" + emacs_real = "#{app}/Contents/MacOS/Emacs-real" path = PATH.new(ORIGINAL_PATHS) - puts "Patching plist at #{plist} with following PATH value:" + puts "Creating wrapper script with following PATH value:" path.each_entry { |x| puts x } - system "/usr/libexec/PlistBuddy -c 'Add :LSEnvironment dict' '#{plist}'" - system "/usr/libexec/PlistBuddy -c 'Add :LSEnvironment:PATH string' '#{plist}'" - system "/usr/libexec/PlistBuddy -c 'Set :LSEnvironment:PATH #{path}' '#{plist}'" - system "/usr/libexec/PlistBuddy -c 'Print :LSEnvironment' '#{plist}'" + # Escape single quotes for use within single-quoted shell string + # Replace ' with '\'' (end quote, escaped quote, start quote) + escaped_path = path.to_s.gsub("'", "'\\''") + + # Rename original binary + File.rename(emacs_binary, emacs_real) unless File.exist?(emacs_real) + + # Create wrapper script with relative path for relocatability + File.open(emacs_binary, "w") do |f| + f.write <<~EOS + #!/bin/sh + if [ -z "$EMACS_PLUS_NO_PATH_INJECTION" ]; then + export PATH='#{escaped_path}' + fi + exec "$(dirname "$0")/Emacs-real" "$@" + EOS + end + + # Make executable + File.chmod(0755, emacs_binary) system "touch '#{app}'" end