Question

I wrote a script that convert a icns file to png and then encode the png with base64.

I could do it in 2 steps:

  • sips -s format png test.icns -o test.png
  • base64 -w0 test.png

But since test.png is just an intermediary file, I'd like to pipe the output of the 1st command directly to base64, how do I do that?

Note that sips doesn't seem to support /dev/stdout as the argument of -o.

Was it helpful?

Solution

The sips utility does not support outputting to stdout unfortunately, so you cannot directly pipe the resulting file into another program. And as you have already tested, it also does not support using /dev/stdout or a named pipe or similar, as it will recreate the file when outputting.

However, you can use ordinary shell scripting "tricks" to make a "one-liner" for combining the commands if you wish to do so:

 sips -s format png test.icns -o __$$ && base64 __$$ && rm __$$

Note that this is for Bash, and that it will create and delete a temporary file named __.

Also note that I have removed the -w0 parameter in your question from the base64 command. That is a parameter you would use on for example the Linux version of the base64 command, but the macOS command does not have such a parameter. Indeed that wrapping behaviour you request with that parameter is already on by default on macOS.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top