2

该资源的长期用户,第一次提问者。我正在尝试编写一个简短的 Applescript,它允许我选择一个 .svg 文件并使用 quicklook (qlmanage) 函数来生成一个快速而肮脏的 .png 转换。我希望它非常灵活,所以安装 ImageMagick 不是一个选项。这是代码:

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

非常简单,但根本不起作用(这给了我一个 Applescript 错误,并弹出 qlmanage 帮助对话框)。我尝试了一些变体,我觉得我需要在 -o 之后的第一个参数中声明 FOLDER 并在第二个参数中声明 PATH 。但我一直无法做到这一点。请记住,我是这方面的新手。

4

2 回答 2

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

于 2012-10-21T21:31:00.770 回答
0

查看 qlmanage 的手册页显示没有“-o”选项。唯一的输出选项是打开的调试窗口。我认为不可能获得 png 输出。但是,我编写了一个名为 qlpreview 的命令行工具来完成此任务。在这里找到它以及显示如何使用它的 applescript 代码。

于 2012-10-19T13:25:59.553 回答