Unarchive WITHOUT deleting original archive

I would like to use the "Unarchive" action without it deleting/trashing the original archive.
This is so that I can easily perform actions on the unarchived content, (ie. move to enclosing folder, set label Red)
while still preserving the original archive for later use, (ie. seeding a torrent, keeping the archive since its smaller and I only needed the contents for temporary processing.)
I could just tell Hazel to open the archive with an external program, but this makes it difficult to easily process the resulting files.
Does anyone know how to prevent the "Unarchive" action from trashing the originals?
Or, is there a way I can mimic the action with my desired modifications via Applescript?
*EDIT——————
Just in case this thread goes unanswered, I'll post my own findings in case someone else searches for this.
After some research of my own I came up with this applescript which unrars archives without deleting the original content, then moves the product out of up into the parent directory and sets some colour labels.
* note that you will need to point the script to an unrar executable; if you installed it from macports the path should be /opt/local/bin/unrar.
* I found that I needed to use the applescript for any subsequent actions on the product of the unarchiving process; for some reason I couldn't get the hazelSwitchFile variable to work. This is probably since I'm fairly new to applescript and am unsure of the proper formatting for this variable's contents.
This is so that I can easily perform actions on the unarchived content, (ie. move to enclosing folder, set label Red)
while still preserving the original archive for later use, (ie. seeding a torrent, keeping the archive since its smaller and I only needed the contents for temporary processing.)
I could just tell Hazel to open the archive with an external program, but this makes it difficult to easily process the resulting files.
Does anyone know how to prevent the "Unarchive" action from trashing the originals?
Or, is there a way I can mimic the action with my desired modifications via Applescript?
*EDIT——————
Just in case this thread goes unanswered, I'll post my own findings in case someone else searches for this.
After some research of my own I came up with this applescript which unrars archives without deleting the original content, then moves the product out of up into the parent directory and sets some colour labels.
- Code: Select all
set temp to "______folder_name_unlikely_to_already_be_present_in_this_directory_here___this_should_work__"
set extensionList to {"mp4", "mkv", "avi", "ts"}
tell application "Finder"
set posix_parent_dir to POSIX path of (container of (item theFile) as string)
set posix_grandparent_dir to POSIX path of (container of (item (posix_parent_dir as POSIX file)) as string)
do shell script "mkdir " & quoted form of (posix_parent_dir & temp)
do shell script "____insert_path_to_unrar_here______ e " & quoted form of (POSIX path of (item theFile as string)) & " " & quoted form of (posix_parent_dir & temp)
set extractedFiles to every file of folder (posix_parent_dir & temp & "/" as POSIX file)
repeat with i from 1 to the count of extractedFiles
if (the name extension of the (item i of extractedFiles) is in the extensionList) then
set label index of (item i of extractedFiles) to 2 -- red
do shell script "mv " & quoted form of (POSIX path of ((item i of extractedFiles) as string)) & " " & quoted form of posix_grandparent_dir
else
do shell script "rm -rf " & quoted form of (POSIX path of ((item i of extractedFiles) as string))
end if
end repeat
do shell script "rm -rf " & quoted form of (posix_parent_dir & temp)
-- replace '2' above with the number for the color you'd like to use:
-- 0=none, 1=orange, 2=red, 3=yellow, 4=blue, 5=purple, 6=green, 7=grey
set label index of (item (posix_parent_dir as POSIX file)) to 7
end tell
* note that you will need to point the script to an unrar executable; if you installed it from macports the path should be /opt/local/bin/unrar.
* I found that I needed to use the applescript for any subsequent actions on the product of the unarchiving process; for some reason I couldn't get the hazelSwitchFile variable to work. This is probably since I'm fairly new to applescript and am unsure of the proper formatting for this variable's contents.