I'm trying to create a script that will output a png file from an icns file using sips command.
The script uses read to capture path to icns file, and to capture name of the png file it outputs.
The script outputs the png file to /private/tmp/
directory...or it should:
#!/bin/sh
# Prompt for source file
/usr/bin/read -p "Drag ICNS source file into Terminal and hit RETURN: " SOURCEFILE
# Prompt for output file name
/usr/bin/read -p "Provide output file name (no spaces!) an hit RETURN: " OUTPUTFILE
# Create file
/usr/bin/sips --setProperty format png --resampleHeightWidthMax 128 "$SOURCEFILE" --out /private/tmp/"$OUTPUTFILE"
exit 0
The script is executable (755). I navigate to the folder and run the script (using obligatory "./" since I'm in the directory the script is in). I'm using BBEdit 12 for test. Here is what I get:
$ ./createIconJSS120png.sh
Drag ICNS source file into Terminal and hit RETURN: /Applications/BBEdit.app/Contents/Resources/BBEditApplication.icns
Provide output file name (no spaces!) an hit RETURN: BareBones_BBEdit12.png
Warning: not a valid file - skipping
Error 4: no file was specified
Try 'sips --help' for help using this tool
I tried using using quotes, in case there is ever a space in the icns path:
"$SOURCEFILE"
I also tried using:
"${SOURCEFILE}"
Running the command manually works fine, so pretty sure it is an issue with the read input:
$ /usr/bin/sips --setProperty format png --resampleHeightWidthMax 128 /Applications/BBEdit.app/Contents/Resources/BBEditApplication.icns --out /private/tmp/BareBones_BBEdit12.png
/Applications/BBEdit.app/Contents/Resources/BBEditApplication.icns
/private/tmp/BareBones_BBEdit12.png
Any ideas why the read command is not capturing input and passing to the script?