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:
tell application "Finder"
set currentDir to POSIX path of ((container of (path to me)) as text)
end tell
tell application "Terminal"
do script "cd " & currentDir
do script "<operation goes here>"
end tell
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?