Simple script to rename nzb files for SABnzbd+

I have set this simple script up to rename nzb files (if you don’t know what these are then don’t ask, just try a Google search) for use with SABnzbd+ and it’s categories.
If you just change the destination folder to the folder you have set up within SABnzbd+ that scans for any nzb files and the {{blah blah}} to the category name(s) you have set up within SABnzbd+ you need to keep the {{ }} as this is what tells SABnzbd+ what the category is.

Hope someone will find this as useful as I do :wink:

-- Created by A. Robertson 17th Sept 2011

-- This script will run as a folder action. It will take all the files dropped into the folder and search for any with the type nzb and then rename them all with a prefix for use by SABnzbd+ and its categories. You can rename anything within the {{...}} to any of the category types you have set up and then when SABnzbd+ loads the nzb file in it will have the category automatically set. All the .nzb files are renamed and then copied to the nzb folder, then deleted from the original folder.

-- I have my nzb folder on my NAS drive, but you can change theDestFolder location to your own location that you have SABnzbd+ looking in for nzb files.

-- I had issues with the duplicate as it was sending multiple copies of files over if there were quite a number to be done. Didn't think that all I had to do was another repeat for the files to be copied. Doh!

on adding folder items to this_folder after receiving dropped_items
	tell application "Finder"
		set theDestFolder to POSIX file "/Volumes/NZB" as alias -- change to your SABnzb+ look up folder
		set theFiles to (files in this_folder whose name ends with ".nzb")
		set theCount to number of items in theFiles
		repeat with i from 1 to theCount
			set oneFile to item i of theFiles
			set AppleScript's text item delimiters to ":"
			set this_parent_dir to (text items 1 through -2 of (oneFile as string)) as string
			set this_name to (text item -1 of (oneFile as string)) as string
			set this_ext to ""
			if this_name contains "." then
				set AppleScript's text item delimiters to "."
				set this_ext to the last text item of this_name
				set final_name to (characters 1 thru 1 of this_name) as string
			end if
			if final_name is not "{" then
				set the name of oneFile to (("{{blah blah}}") & (the name of oneFile) as text) -- change to your SABnzb+ category name
				delay 1
			end if
		end repeat
		set copyFiles to (files in this_folder whose name starts with "{{blah blah}}") -- change to your SABnzb+ category name
		set copyCount to number of items in copyFiles
		repeat with i from 1 to copyCount
			set twoFile to item i of copyFiles
			duplicate twoFile to theDestFolder
		end repeat
		delete copyFiles
	end tell
end adding folder items to