1

I have some shell (Bash) scripts that process some video files in a directory. Instead of everytime launching a (Open)Terminal window, then typing the script name, I'd prefer to install an icon in the Finder's explorer toolbar so that a simple click on it does the job (like OpenTerminal does, if you know that tool). The result I imagine is this one :

  • click on the icon

  • a terminal window appears which automatically does a kind of

    cd /the/path/where/I/was/in/the/finder/window; run_my_script.sh
    

Any idea how to do that ? (it's feasible since OpenTerminal does it)

Zombo
  • 1
  • 62
  • 391
  • 407
user1458153
  • 115
  • 1
  • 8

2 Answers2

1

Save something like this as an application in AppleScript Editor:

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
Lri
  • 26,768
  • 8
  • 84
  • 82
0

Add to top of the script,

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

After that run following command on the terminal

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

Adem Öztaş
  • 20,457
  • 4
  • 34
  • 42
  • no, this is exactly what I'd like to avoid. Besides, I don't want to hardcode the current path into the script. I want the script execute in the current folder (the one displayed by the finder), like OpenTerminal does – user1458153 Jan 21 '13 at 16:30