Sample Header Ad - 728x90

macOS: Double click on a file and display the output from a CLI command on the file?

2 votes
2 answers
668 views
There is a file type called "netCDF". My goal is to be able to double click on a netCDF file on Finder and see the text output from a CLI command to which the filename is given. Specifics: There is a command-line command that displays the table of contents of a netCDF file:
`
$ ncdump -h yourfile.nc
` This command shows the table of contents of the netCDF file to the current terminal. **How can I see the same output when I double click on the file on Finder?** **Edit: The following is a description of a failed approach.** I have made some progress toward a solution. Following this thread https://apple.stackexchange.com/questions/224394/how-to-make-a-mac-os-x-app-with-a-shell-script I've been able to create a macOS "app" which is actually a shell script:
`sh
#!/bin/sh
/usr/local/bin/ncdump -h "$@"
` So far, I've been able to verify that I can invoke this "app" from Finder and that the above shell script is actually run. But, I found that the shell script doesn't get the filename as a command line argument. (You can see what's going on by modifying the line to /usr/local/bin/ncdump -h "$@" > $HOME/tmp/logfile.txt 2>&1) So, I have two specific questions 1. How can a shell script (as app) get the filename when invoked from Finder? 2. To which GUI app should it send its stdout and how?
Asked by Ryo (161 rep)
Sep 2, 2022, 04:23 AM
Last activity: May 5, 2025, 03:08 AM