Skip to main content
1 of 2

The answer given by @user3439894 is great, I just improved the Unrar script so that it extracts an archive despite already having the folder with the same name in the directory:

unrar_exe="/usr/local/bin/unrar"
unrar_args="x -ad -idq"

cd "$(dirname "$1")" || exit

for f in "$@"; do
    [ "${f##*.}" == "rar" ] || continue
    d="${f##*/}"
    if [ ! -w "${PWD}" ]; then
        cd "${HOME}/Desktop" || exit
    fi
    if [ -d "${d%.*}" ]; then
        d="${d%.*} $(date '+%Y-%m-%d at %I.%M.%S')/"
    fi
    $("${unrar_exe}" ${unrar_args} "$f" "$d")
done