MacOS – AppleScript from Terminal unrar command

applescriptcommand linemacosterminal

I would like to know if it's possible to make an AppleScript of the following terminal command(s).

cd
unrar e -r -o- *.rar && find ./ -name “*.r*” -delete

Also, I would like to know if it's possible to tweak the unrar e -r -o- *.rar command.

Following situation:

Main_folder\SubfolderA
Main_folder\SubfolderB
Main_folder\SubfolderC

When I login in to Terminal and use the command unrar e -r -o- *.rar, everything from the subfolders will be extracted to the Main_folder.

Is there a command that will extract the *.rar in the same subfolder as where they are stored?

For now I have…

on run {input, parameters}
  tell application "Terminal"
    activate
    do script with command "cd /Volumes/******_storage/******* && unrar e -r -o- *.rar && find ./ -name “*.r*” -delete"
  end tell

This works fine except that subfolders are still extracted in /******** instead of their own folder and that my files aren't deleted.

Best Answer

In the help text of the utility is says...

UNRAR 5.10 beta 4 freeware      Copyright (c) 1993-2014 Alexander Roshal

Usage:     unrar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract>

so you can include the path_to_extract at the end of the command and once inside a loop it's easy. Like this...

cd <path>
for f in `find . -name "*.r*"`; do unrar e -o- $f `dirname $f` && rm $f; done

HTH