2

long time user of this resource, first time questioneer. I'm trying to write a brief Applescript that will allow me to choose an .svg file and use the quicklook (qlmanage) function to generate a quick-and-dirty .png conversion. I want this to be pretty flexible, so installing ImageMagick is not an option. Here's the code:

set thefile to POSIX path of (choose file)
do shell script "qlmanage -t -s 640 -o " & thefile as text

Pretty simple, but does not work at all (this gives me an Applescript error, with the qlmanage help dialog popping up). I've tried a few variations and I get the sense that I need to state the FOLDER in the first argument after -o and the PATH in the second argument. But I have been unable to accomplish this. Keep in mind that I am a newbie at this.

2 Answers2

0

Looking at qlmanage's man page shows there is no "-o" option. The only output option is the debug window that opens up. I don't think it's possible to get a png output. However I have written a command line tool called qlpreview to accomplish this task. Find it here along with applescript code showing how you might use it.

regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • -o is supposedly to "output result in directory" which prevents the preview from opening and (presumably) outputs the .png result. I will, however, take a look at your suggested command line tool. Thanks! – user1758478 Oct 19 '12 at 17:53
0

You need to tell the command where to output the file. I.e what Directory. You place the path to the directory after the -o option.

Because of where you placed the -o option, your script was actually missing the path to the source file. Which goes before the -o option.

When dealing with do shell script. You should remember to use quoted form of

This will escape space in the file/path names. Spaces in unix commands will be interpreted as part of the command. i.e the end of one argument in the command and the start of the next. where you have a file/path with a space in it like photo copy.jpg; photo will be seen as the file/path and copy.jpg will be seen as the next part of the command. single quotes around 'photo copy.jpg' ail correct this.

Try this.

    set file_Path to POSIX path of (choose file)
set save_path to POSIX path of (choose folder)
do shell script ("/usr/bin/qlmanage -t -s640 " & quoted form of file_Path & space & " -o " & quoted form of save_path)

Also @regulus6633. if you use the -h option (displays extensive help.) you will see the part about output to file

markhunte
  • 6,805
  • 2
  • 25
  • 44