使用苹果脚本或自动机应用程序中的命令行使用应用程序打开文件

时间:2017-07-21 00:46:32

标签: macos terminal applescript automator

我希望能够双击以在特定应用程序(SeaMonkey作曲家)中打开文件类型(HTML)。

双击该文件打开SeaMonkey Browser,但我希望它在Seamonkey Composer中打开。唯一的方法是使用以下命令行

seamonkey -editor "filename.html"

那么,如何使用apple脚本或automator在composer中打开我的html文件?

2 个答案:

答案 0 :(得分:0)

如果您想使用AppleScript执行此操作,这个简单的脚本应该可以完成这项任务:

set filePath to ((path to documents folder) as text) & "filename.html"
tell application "Seamonkey Composer" to open filePath

我没有测试Seamonkey Composer应用程序,但它适用于BBEdit。 请注意,open命令必须具有该文件的完整路径。

答案 1 :(得分:0)

将以下脚本保存为脚本编辑器中的应用程序:

on run filesList
    repeat with fileRef in filesList
        do shell script "seamonkey -editor " & quoted form of POSIX path of fileRef
    end repeat
end run

选择查看>显示捆绑包内容并为其提供自定义捆绑包ID。然后,您可以按上述方式更改文件关联。

以上假设seamonkey命令本身只是一个启动器;如果它实际上是完整的应用程序(可能是因为它显然不是原生的Mac应用程序),中间行需要调整一下:

do shell script "nohup seamonkey -editor " & quoted form of POSIX path of fileRef & " >/dev/null 2>&1"

这应该允许shell脚本在seamonkey进程启动后立即退出,使Seamonkey保持运行直到您从GUI退出它。