• Uncategorized

About linux : Execute-MacLinux-shell-script-from-FinderBrowser-in-the-current-folder

Question Detail

Good morning to everybody!

I have created a super-simple script that delete several files in the folder:

rm *.ext1 *.ext2 file1.txt file2.txt

When I execute the script using the shell all works fine. But I’d like to be able to double-click on the script to execute it…and this actually works but it is like the script is executed in another folder and then the answer I get is a list of “rm -filename- : No such file or directory”.

How can I modify my script in order to tell him to be executed in the folder in which it is located? NB: I don’t know a priori the folder path, then I cannot specify the full path!


Question Answer

You could ask the Finder (on Mac) to tell you which folder it is currently displaying:


# Ask Finder which folder it is currently displaying
dir=$( /usr/bin/osascript <<EOF
    tell application "Finder"
            set currFolder to POSIX path of (folder of the front window as alias)
    on error
            set currFolder to "ERROR"
    end try
    end tell
echo "Finder is currently in: $dir"

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.