如何从finder启动shell脚本

时间:2013-01-21 14:31:53

标签: macos shell terminal launching

我有一些shell(Bash)脚本可以处理目录中的一些视频文件。 而不是每次都启动(打开)终端窗口,然后键入脚本名称,我宁愿在Finder的资源管理器工具栏中安装一个图标,这样只需点击它就能完成工作(如OpenTerminal所做的那样,如果你知道那个工具)。我想象的结果就是这个:

  • 点击图标

  • 出现一个自动执行某种

    的终端窗口
    cd /the/path/where/I/was/in/the/finder/window; run_my_script.sh
    

知道怎么做吗? (自OpenTerminal以来这是可行的)

2 个答案:

答案 0 :(得分:0)

添加到脚本顶部,

  #!/bin/bash
  cd /the/path/where/I/was/in/the/finder/window  
  ....
  ....

之后在终端上运行以下命令

ln -s run_my_script.sh /bin/run_my_script.sh

答案 1 :(得分:0)

将此类内容保存为AppleScript编辑器中的应用程序:

activate application "SystemUIServer" -- http://www.openradar.me/9406282
tell application "Finder"
    activate
    set p to POSIX path of (insertion location as text)
end tell
tell application "Terminal"
    activate
    do script
    repeat while contents of window 1 starts with linefeed
        delay 0.01 -- wait to get a prompt
    end repeat
    do script "cd " & quoted form of p in window 1
    do script "uptime" in window 1
end tell