Later edit: simple solution used later seems to be to just use a .command file which would launch OpenSpace in a terminal similar to using a .sh file on Linux. We can also put any required variable initialization there - like Start-OpenSpace.command which has
#!/bin/bash
cd "$(dirname "$0")"
./OpenSpace.app/Contents/MacOS/OpenSpace
Various methods tried -
(has contradictory info? Mac official docs?)
To make a Mac app pick up environment variables when running in debug mode inside Xcode, you can set the environment variables in the scheme settings. Go to your project scheme, select "Edit Scheme," and under the "Run" section, add your environment variables in the "Environment Variables" section.
From Google's AI-assisted search,
To set environment variables for a Mac app so they are available whether the application is launched by double-clicking or from the terminal, you can use several methods depending on your needs. The most reliable methods involve modifying the launch configuration of the app or using system-wide settings. [1, 2, 3, 4]
1. Using a shell script wrapper (Recommended for app distribution) [5]
The most robust approach, especially if you need specific variables bundled with the app itself, is to use a custom shell script as the actual executable, which then launches the real application.
- Modify : Right-click your file and select "Show Package Contents". Navigate to the directory and open the file (using a text editor or Xcode).
- Change Executable: Change the value for the key (CFBundleExecutable) from your app's actual binary name (e.g., ) to a new script name (e.g., ).
- Create the script: In the directory, create the file specified in the (e.g., ).
- Add variables and launch command: Add the following to the script, replacing and / with your own values: [7, 8, 9, 10, 11]
- Make the script executable: Open your terminal, navigate to the directory, and run the command: . [12]
This method ensures the variables are set regardless of how the script is executed. [13]
2. Setting system-wide environment variables (For development or user's own machine)
If you just need these variables on your local machine and want them available for all applications launched in the standard macOS environment (terminal, double-click, etc.), you should add them to your shell configuration file.
- Open a terminal: The file you need to edit depends on your default shell.
- For Zsh (macOS default since Catalina): or
- For Bash (older macOS default): or
- Add variables: Add lines to the appropriate file:
- Apply changes: Restart your terminal or run the source command (e.g., ) for the changes to take effect in the terminal sessions. For applications launched via double-click, you may need to log out and log back in to macOS. [14, 15, 16, 17, 18]
3. Using (Advanced, not recommended in modern macOS) [19]
In older versions of macOS, the file could be used for system-wide settings. This method is deprecated and not guaranteed to work reliably in modern macOS versions [1]. [20, 21, 22, 23]
Summary of methods
| Method [24, 25, 26, 27, 28] | Works from Terminal? | Works from Double-click? | Best For |
| Shell Script Wrapper | Yes | Yes | Distributing an app with specific variables |
| Shell Configuration | Yes | Yes (after login/restart) | Development on your local machine |
AI responses may include mistakes.
[5] https://developer.ansys. com/docs/system-coupling-c- library-2024-r1/md_08__ commandlinearguments.xhtml
[7] https://www.praetorian. com/blog/bypassing-google- santa-application- whitelisting-on-macos-part-2/
[16] https:// reactionmechanismgenerator. github.io/RMG-Py/users/rmg/ installation/ anacondaDeveloper.html
[19] https://superuser.com/ questions/476752/setting- environment-variables-in-os-x- for-gui-applications
No comments:
Post a Comment