OS X 中的文件关联:不会在 args 中传递文件名?



我正在打包一个应用程序到一个。app目录"拖装"或无论它叫什么,我有一个奇怪的问题与文件关联。我将我的应用程序设置为。xyz文件的查看器,当我双击该文件时,系统确实启动了我的应用程序;唯一的问题是,我点击的文件的路径不在args[]中,只有一个参数,类似于~psn_0_901340,我认为是一个时间戳,因为它每次都改变。

所以…我该怎么办?我已经在这里坐了两个小时了,还是找不到解决办法。

我认为你需要的是AppleScript滴。

链接中AppleScript的缩短版本:

on open dropped_files
    set the_command to quoted form of POSIX path of (path to resource "script.sh")
    set file_list to ""
    repeat with file_path in dropped_files
        set file_list to file_list & " " & quoted form of POSIX path of file_path
    end repeat
    set the_command to the_command & file_list
    do shell script the_command
end open

使用Script Editor导出为应用程序。将script.sh放入Resources文件夹

添加您的文件扩展名关联到Info.plist。您可能需要在OS X注意到更改之前启动或移动液滴。允许你双击文件。

如果您想要启动Terminal或捕获脚本输出,请参阅完整的AppleScript。

最新更新