To Applescript pro's: create unrar script

Feature requests not specific to either the Mac OS X or GTK+ versions of Transmission
Superjunior
Posts: 12
Joined: Wed Sep 06, 2006 1:23 pm

To Applescript pro's: create unrar script

Post by Superjunior »

Since I don't know anthing about AppleScripts, I turn to you guys. This script would be wonderful to use as a Folder Action on the finished download's folder to unrar archives.

1. The script (as a folder action) checks what just got added is a folder or a file, it should even check subfolders.

2. It should check for file name endings a.rar, b.rar ... z.rar and 001.rar and open this file only. This is to filter out the start .rar file, since in some archives all files end with .rar and starting the wrong file confuses some unrar apps. Or is there a better way?

3. Open the file (with predefined app, if possible)

4. Close defined app (if possible, or wil this close it during initiated progress?)


What do you guys think? Possible?
softwareelves
Web Interface Developer
Posts: 351
Joined: Thu Mar 23, 2006 10:32 pm

Post by softwareelves »

this is a bit tricky because, u can't start unraring them until they are done, and the folder script couldn't tell if they are complete..... maybe u could suggest that the devs add a "run script on complete" function?
Sean
Posts: 212
Joined: Fri Jul 14, 2006 12:43 am

Post by Sean »

softwareelves wrote:this is a bit tricky because, u can't start unraring them until they are done, and the folder script couldn't tell if they are complete..... maybe u could suggest that the devs add a "run script on complete" function?
Actually Transmission has a preference now to keep incomplete files in a separate location.

So incomplete files would be stored in /Downloads/Incomplete and when they are done they'd just be moved to the /Downloads/ folder... The folder action would need to be attached to the /Downloads/ folder since everything there would be completed.
softwareelves
Web Interface Developer
Posts: 351
Joined: Thu Mar 23, 2006 10:32 pm

Post by softwareelves »

ah ok, well i can work on this in my spare time. i'm a pretty good applescripter :) if your still interested drop me a line at my AIM below.
Superjunior
Posts: 12
Joined: Wed Sep 06, 2006 1:23 pm

Post by Superjunior »

Yeah, I'm still interested :)
I think lot of users would appreciate this.
little nok-nok
Posts: 8
Joined: Mon Nov 13, 2006 3:52 am

Post by little nok-nok »

Actually, you don't need a script at all. You can use Hazel for this. Granted, Hazel is not free, but it's pretty cheap.
thomasshirley
Posts: 64
Joined: Sat Sep 02, 2006 1:45 pm

Post by thomasshirley »

You could throw this together pretty easily in automator, provided you have somthing like 'UnrarX' installed. It's freeware and does the job great.

http://www.unrarx.com/
Superjunior
Posts: 12
Joined: Wed Sep 06, 2006 1:23 pm

Post by Superjunior »

little nok-nok wrote:Actually, you don't need a script at all. You can use Hazel for this. Granted, Hazel is not free, but it's pretty cheap.
Hazel looks nice, but it doesn't do subfolders, does it?
little nok-nok
Posts: 8
Joined: Mon Nov 13, 2006 3:52 am

Post by little nok-nok »

Superjunior
Posts: 12
Joined: Wed Sep 06, 2006 1:23 pm

Post by Superjunior »

little nok-nok wrote:Yes, Hazel does subfolders.
Perfect, seems like it could work just fine. Hazel has the ability to check and filter on the full file name (file name + suffix), a feature Automator lacks.

A free script would still be welcome though :)
jawney
Posts: 1
Joined: Wed Apr 07, 2010 7:37 am

Re: To Applescript pro's: create unrar script

Post by jawney »

Here's an applescript I wrote and set up as a folder action to auto-unrar. I simply open the file which means the default application to open rar files must exist. I use The Unarchiver so it extracts by default.
I realize the code isn't pretty, but it seems to work for me and that's good enough.

***************

on adding folder items to thisFolder after receiving added_items
repeat with added_item in the added_items
process_file(added_item)
end repeat
end adding folder items to


on process_file(source_item)
if is_Folder(source_item) then
set folder_items to list folder source_item
repeat with folder_item in folder_items
set x to POSIX file (POSIX path of source_item & "/" & folder_item)
process_file(x)
end repeat
else
if is_Rar(source_item) then
extract_rar(source_item)
end if
end if
end process_file


on is_Rar(source_file)
set filename to POSIX path of source_file
return (filename ends with ".rar")
end is_Rar


on is_Folder(source_item)
return (folder of (info for source_item))
end is_Folder


on extract_rar(rar_file)
tell application "Finder"
open rar_file
end tell
end extract_rar
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: To Applescript pro's: create unrar script

Post by killemov »

It would be better if the script was called by transmission itself.

Something like: viewtopic.php?t=10364
evinh0
Posts: 3
Joined: Fri Nov 04, 2011 1:38 am

Re: To Applescript pro's: create unrar script

Post by evinh0 »

Hello, I made this script, it will extract all rar files, and then permanently remove everything that was on the folder (.txt, .r01, .rar, etc) and only the file contained in the rar will remain. So, be careful, if you download other stuff (like a game) that has a rar file with it, everything will be deleted but the file contained in the rar.

1 - You will need StuffIt Expander (Free on Mac App Store) for this to work.
2 - The default volume is set to "Macintosh HD", change it if you need to.
3 - You can change it to send files to trash, at the end of the code you should comment 2 lines and uncomment the other.

Code: Select all

#!/bin/sh
exec osascript <<END

on reformat(theName)
	set newName to ""
	repeat with i from 1 to length of theName
		if ((character i of theName) is "/") then
			set newName to newName & ":"
		else
			set newName to newName & character i of theName
		end if
	end repeat
	return newName
end reformat

tell application "Finder"
	set found_rar to false
	set str to "$TR_TORRENT_DIR" & ":" & "$TR_TORRENT_NAME"
	set str to my reformat(str)
	set source_folder to "Macintosh HD" & str & ":"
	
	set item_list to source_folder
	set src_folder to item_list
	set the the_items to list folder item_list without invisibles
	set item_list to item_list as string
	repeat with i from 1 to number of items in the the_items
		set the_item to item i of the the_items
		set the_item to (item_list & the_item) as alias
		set this_info to info for the_item
		if name extension of this_info is "rar" then
			try
				tell application "StuffIt Expander"
					expand the_item
					quit
				end tell
				set found_rar to true
			end try
		end if
	end repeat
	if found_rar then 
		repeat with i from 1 to number of items in the the_items
			set the_item to item i of the the_items
			set the_item to (item_list & the_item) as alias
			
			--Permanently remove it
			set posPath to POSIX path of the_item
			do shell script "rm -rf \"" & posPath & "\""
			
			--Or send to trash
			--delete file the_item
		end repeat
	end if
	
end tell
END

killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: To Applescript pro's: create unrar script

Post by killemov »

evinh0 wrote:Hello, I made this script, it will extract all rar files, and then permanently remove everything that was on the folder (.txt, .r01, .rar, etc) and only the file contained in the rar will remain. So, be careful, if you download other stuff (like a game) that has a rar file with it, everything will be deleted but the file contained in the rar.
...
Will this script run from transmission every time a torrent has finished downloading?
evinh0
Posts: 3
Joined: Fri Nov 04, 2011 1:38 am

Re: To Applescript pro's: create unrar script

Post by evinh0 »

Yes, see transmission settings to include this. Mac only.
Post Reply