0

I have a simple .sh type script and I want to be able to double click on it from my desktop to open it. I assume I could do this with an .exe file, but if there is another way, please let me know. I am on a mac.

My script is:

cd ..
open .trash
exit
  • 1
    Does this answer your question? [How do I make this file.sh executable via double click?](https://stackoverflow.com/questions/8409946/how-do-i-make-this-file-sh-executable-via-double-click) – SleighBoy Jan 11 '20 at 04:53
  • Note that if you did not include the `exit` line, the shell would exit anyway when the `open` command finishes. You could drop that line. Are you sure you only want to go up a directory level rather than changing to your home directory? Should you use `cd $HOME/.Trash`? (I used `.Trash` rather than `.trash` to match the case of the trash directory, though the macOS file system is case-insensitive by default, so it doesn't really matter.) – Jonathan Leffler Jan 11 '20 at 04:58
  • And the detailed answer to your headline question is: `#include ` — `#include ` — `int main(void) { chdir(".."); system("open .Trash"); return 0; }` —— Compile and run. The '—' dashes mark mandatory newlines. Dealing with `cd $HOME` is marginally more complex: `const char *home = getenv("HOME"); chdir(home);`. You should never have a program run without HOME being set in the environment, but you could check for it if you wish. – Jonathan Leffler Jan 11 '20 at 05:03

0 Answers0