Running a Shell Script From Finder and Keeping the Filepath
If you’re a macOS user and want to run a shell script by double-clicking it in the Finder, you might encounter an issue with the working directory. By default, the working directory of the script becomes the user’s home directory, which can lead to unexpected behavior if your script relies on relative file paths. To ensure that your script runs with the correct working directory, you can include a specific command at the beginning of your script.