I'm trying to extract the icon from an xattr of a file. Using xattr to get the "com.apple.ResourceFork" in hex format i use:
xattr -px com.apple.ResourceFork file
and save the output to a variable
var="$(xattr -px com.apple.ResourceFork file)"
then using variable expansion i remove the first bytes until i reach 69 (icns magic number is 69 63 6E 73)
var=${var#*69 63 6E 73}
next i output the variable and append "69 63 6E 73" to the beginning to restore the magic number.
echo "69 63 6E 73$var" > output.txt
if i take the hex data from the output.txt and insert it into a hexeditor to save it then it works and the .icns is created.
i want to do this programmatically in bash/zsh without having to save it manually.
tried using
touch icon.icns
to create an empty file then
echo "69 63 6E 73$var" > icon.icns
just transforms the output file into an ASCII file.
i'm not stuck to my method, any working method is acceptable to me.