Automator,AppleScript还是其他?

时间:2012-04-09 10:30:51

标签: macos cocoa automation applescript

我需要通过立即传递一系列参数来自动化我的应用。在Windows中,我将它们全部作为命令行从快捷方式传递,但我需要对OSX执行相同的操作。

我一直在看AppleScript,但似乎我需要单独发送每个参数,如tell myapp to use <x>然后tell myapp to use <y>。 Automator看起来可以做我想做的事,但看起来太复杂了。

我的最终目标是通过将文件拖放到桌面上的图标上来发送一系列文本参数,然后发送文件路径列表。

实现这一目标的最佳方式是什么?

1 个答案:

答案 0 :(得分:1)

如果我理解正确,有问题的应用程序接受命令行参数。然后,您只需要一个AppleScript droplet ,它接收文件并将其路径作为(以空格分隔的)参数传递给shell命令:

on open these_items
    set file_args to ""
    repeat with one_item in these_items
        set file_args to file_args & " " & quoted form of POSIX path of one_item
    end repeat
    set command to "open" -- replace this with your shell command + arguments
    do shell script (command & file_args)
end open

(基于this forum post