title: Getting Finder's current directory in AppleScript stored as application
body: <p>I have tried to make an AppleScript that is supposed to read the current directory from Finder and run a shell command on it. If I navigate to the desired folder in Finder and run the script from AppleScript Editor it works, but when I saved the script and dragged it to the Finder toolbar, currentDir is set to the folder of the script file (my user directory). Here is my script:</p>
  
  <pre><code>tell application "Finder"
      set currentDir to POSIX path of ((container of (path to me)) as text)
  end tell
  tell application "Terminal"
      do script "cd " &amp; currentDir
      do script "&lt;operation goes here&gt;"
  end tell
  </code></pre>
  
  <p>How can I get the directory active when I use the toolbar shortcut?
  Second, is there a way to run the shell command in the background, without opening (showing) the Terminal window?</p>