To Applescript pro's: create unrar script
-
- Posts: 12
- Joined: Wed Sep 06, 2006 1:23 pm
To Applescript pro's: create unrar script
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?
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?
-
- Web Interface Developer
- Posts: 351
- Joined: Thu Mar 23, 2006 10:32 pm
Actually Transmission has a preference now to keep incomplete files in a separate location.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?
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.
-
- Web Interface Developer
- Posts: 351
- Joined: Thu Mar 23, 2006 10:32 pm
-
- Posts: 12
- Joined: Wed Sep 06, 2006 1:23 pm
-
- Posts: 8
- Joined: Mon Nov 13, 2006 3:52 am
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.
-
- Posts: 64
- Joined: Sat Sep 02, 2006 1:45 pm
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/
http://www.unrarx.com/
-
- Posts: 12
- Joined: Wed Sep 06, 2006 1:23 pm
Hazel looks nice, but it doesn't do subfolders, does it?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.
-
- Posts: 12
- Joined: Wed Sep 06, 2006 1:23 pm
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.little nok-nok wrote:Yes, Hazel does subfolders.
A free script would still be welcome though
Re: To Applescript pro's: create unrar script
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
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
Re: To Applescript pro's: create unrar script
It would be better if the script was called by transmission itself.
Something like: viewtopic.php?t=10364
Something like: viewtopic.php?t=10364
Re: To Applescript pro's: create unrar script
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.
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
Re: To Applescript pro's: create unrar script
Will this script run from transmission every time a torrent has finished downloading?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.
...
Re: To Applescript pro's: create unrar script
Yes, see transmission settings to include this. Mac only.