1

I am trying to use the following command to find all PDFs in the current directory (not recursively) - however I don't think it likes the '{}' on the --out.

find . -iname "*.pdf" -maxdepth 1 -exec sips -s format jpeg --resampleHeightWidth 129 100 '{}' --out '{}'.jpg \;

The find work when used with -print and sips works when I specify the name --out test.jpg. Any way to make this work? Or should I try xargs? I don't really want to use a loop for simplicity... Any ideas?

UPDATE: I attempted using xargs - but again get an error out_dir_not_found.

find . -iname "*.pdf" -maxdepth 1 -print0 | xargs -0 -I % sips -s format jpeg --resampleHeightWidth 129 100 % --out "%.jpg"


mymbpro:pdfs dh$ find . -iname "*.pdf" -maxdepth 1 -print0 | xargs -0 -I % sips -s format jpeg --resampleHeightWidth 129 100 % --out "%.jpg"
Error 10: out_dir_not_found /Users/darenhunter/Desktop/pdfs/ATTENTION.pdf.jpg
Try 'sips --help' for help using this tool
Error 10: out_dir_not_found /Users/darenhunter/Desktop/pdfs/DisNCLB119.pdf.jpg
Try 'sips --help' for help using this tool
Error 10: out_dir_not_found /Users/darenhunter/Desktop/pdfs/services2012.pdf.jpg
Try 'sips --help' for help using this tool
Error 10: out_dir_not_found /Users/darenhunter/Desktop/pdfs/Fall2011.pdf.jpg
Try 'sips --help' for help using this tool
broccolifarmer
  • 465
  • 7
  • 15
  • Try your original find command, but with an echo: `-exec echo sips ...`. Do the commands it outputs work when you run them at a prompt? Does it ask for any information? – that other guy Jan 29 '13 at 21:05

1 Answers1

2

If you will be executing over many results, it is more efficient to pipe the results to the xargs command instead. xargs is a more modern implementation, and handles long lists in a more intelligent way. The print0 option can be used with this.

The following command will ensure that filenames with whitespaces are passed to the executed COMMAND without being split up by the shell. It looks complicated at first glance, but is widely used.

find . -print0 | xargs -0 COMMAND

ref

Zombo
  • 1
  • 62
  • 391
  • 407