Which means people will have to install Haskell, which (presumably, I've not done it) means they'll also have ~/.ghcup/bin/runhaskell. So I suggest you test for that, use it if it's there, and throw a "Please locate..." prompt if it isn't.
The problem is many users use Stack, other use ghcup, etc...many things can go wrong, so I would like to find the executable in the system, if possible.
Then check for the file in the places you know it might be, then ask the user if you can't find it.
Trawling even just their user folder with find could take a while, and will have an impact on their machine's performance. locate would be faster but, as said earlier, is unlikely to work as few people will have a pre-built database. mdfind won't work when, like yours, runhaskell is under a . directory.
Or maybe use an AppleScript in KM to fire up a Terminal window and run which in that -- running in the user's "normal" space it'll have PATH as it was set by the haskell install, so should give you the right answer. Again, disruptive -- so worth popping an information dialog to let the user know what's happening and why.
My idea is this one: I would like to search the path in each of those locations. To accomplish that, I would need to read the file, and obtain the list of comma separated values of the PATH variable in each of those paths.
Do you think that is possible ?
That would be my first step. If nothing is found, then they user should enter the path.
Your suggestion is better than searching the whole drive for the executable, I think. That was one of my first thoughts.
which searches through the locations in the user's $PATH, so to reimplement it you'd have to get their $PATH -- by which time you don't need which!
So just do what you need in the user's environment. Something like this -- the enabled AppleScript action will get you the full runhaskell path. Disable that and enable the one below and you'll get their full $PATH, useful if your macro is using other Unixy bits and pieces.
My previous post was more accurate. I am trying to find a way to extract the PATH variable in ~/.bashrc for example and use that information to find the executable.
Since there are a number of possible environmental set-up files, I think employing the user's Terminal to acquire their path is a pretty good way to go.
Another possibility is to locate the appropriate set-up file:
find ~ -maxdepth 1 -type f -iname "*profile*"
And then use source to load it and read the resultant shell variables.
When I know what file I'm dealing with I use source – otherwise I use the Terminal method.
Thank you so much, @ccstone ! I would like to experiment with something like this.
In my case, that command returns:
~/.zprofile
and the contents are:
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
However, my $PATH variable is in ~/.zshrc
and one of the lines is:
The complexity here is that you have to be aware of all the possible places the user's $PATH might have been changed, and there are quite a few options.
For instance my set-up is all in my ~/.profile file, so I don't have to monkey with different set-ups for different shells.
I used to have a pretty comprehensive list, but it's lost to time – so you'll have to do your own research. Here's a start:
You have your work cut out for you if you really want to pursue this route, as there are many possible config files and not necessarily just one per each shell variant.
I haven't researched this at length in years, and it was a royal pain when I did it originally – many, many hours spent...