Pass selected file path to a shell script

Hi -- I'm messing around with creating custom icons, and the final step of the process is co create an ICNS file with the terminal command iconutil -c icns [folder path]


I can open the terminal and type in iconutil -c icns, then drop the .iconset folder into the terminal window to get its path and run the script, but I thought it would be more efficient to create a quick action called Make ICNS that I could run from a contextual menu.


I set the Quick Action to receive the current folders in Finder, added a Get Selected Finder Items call, then called Run Shell Script, but I can't figure out how to pass the selected file path into the shell script. Everything I've tried so far just returns an error.




Any suggestions?

Thanks!


-- Lou

Posted on Dec 16, 2020 4:15 PM

Reply
Question marked as Top-ranking reply

Posted on Dec 16, 2020 4:26 PM

I don't have time to dig into the iconset format. But I created a copy of your workflow that just echoes the folders to a file. The only difference with your is that I'm using zsh instead of tcsh. But the default script it gave me is this:


for f in "$@"

do

echo "$f" > /tmp/files.txt

done


The only change I made was to redirect the output of the echo command. It worked.

Similar questions

9 replies
Question marked as Top-ranking reply

Dec 16, 2020 4:26 PM in response to LouBenjamin

I don't have time to dig into the iconset format. But I created a copy of your workflow that just echoes the folders to a file. The only difference with your is that I'm using zsh instead of tcsh. But the default script it gave me is this:


for f in "$@"

do

echo "$f" > /tmp/files.txt

done


The only change I made was to redirect the output of the echo command. It worked.

Dec 17, 2020 9:47 AM in response to VikingOSX

Thanks! Do you do a lot of command line stuff with Terminal? My impression is that the version of bash that's installed in macOS is very old, and many of the folks who swear by that shell have installed updates over the system-installed version. Word is that Apple no longer defaults to bash, and they have deprecated it, with plans to remove it in future releases.


Actually, the script that you shared with me did not work in bash. It didn't throw any errors, but it failed to generate the icns file. To reference the array element properly, I needed to use "$f", not "${f}". I didn't bother to add exit 0, but I don't think it makes any difference.


Still, your code snippet pointed me in the right direction, and I appreciate that. So, thanks again!

Dec 17, 2020 10:06 AM in response to LouBenjamin

LouBenjamin wrote:

My impression is that the version of bash that's installed in macOS is very old, and many of the folks who swear by that shell have installed updates over the system-installed version. Word is that Apple no longer defaults to bash, and they have deprecated it, with plans to remove it in future releases.

I’ve been using zsh for years, long before Apple started pushing people to it. zsh is every bit as powerful as bash, and virtually identical. If you had lots of very low-level bash plugins or other modifications, then you might want to keep using bash. But otherwise, most of the reason people use bash is actually the same reason Apple doesn’t - the viral GPL license. It was originally designed to stop Apple (I mean just Apple) from using GNU source code. Then, it was upgraded to ensure that it could not be used in any part of the Apple ecosystem. This way, GPL-licensed code can only be used by companies like Amazon, Facebook, and Google, who do not re-distribute it. Some people say that was always the plan.

Dec 16, 2020 11:10 PM in response to VikingOSX

I have to thank you and share that your feedback set me on the path to the proper solution. Along the way, I discovered that bash is deprecated and that zsh has been the default shell since somewhere around Catalina. How my terminal ended up running tcsh, I have no idea. Once I switched to zsh and selected "as parameters" Automator wrote a for loop that referenced the parameter. I just needed to substitute the call to iconutil.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Pass selected file path to a shell script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.