Label and hide extension of new files added to folder

Hi,

I have SABnzbd+ set up to automatically download new episodes of shows i watch via RSS, then rename them to “S01E01 - Episode Name” and put them in the correct sub-folder in my “TV Shows” folder.

This all works great, but i still have to give every new (and thus unwatched) episode a grey finder label and hide the extension manually. It would be great if this would also go automatically with Applescript.

So what i need is every new file added to a subfolder in my “TV Shows” folder to be labeled grey and the extension to be hidden.

Example image

“S06E13 - The Last Recruit.mkv” needs to be labeled grey and have it’s extension hidden.

The path looks like this:
/Volumes/Lacie HD/TV Shows/Lost (Season 6)/S06E13 - The Last Recruit.mkv

A nice fellow on a Dutch forum made this for me:

on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		repeat with myFile in these_items
			set label index of myFile to 7 --grey
			set extension hidden of myFile to true
		end repeat
	end tell
end adding folder items to

But there are some problems:

1st, This script needs to be applied to every single subfolder in the “TV Shows” folder, instead of just to the “TV Shows” folder itself.

2nd, When i move a file to the folder myself it works great, but SABnzbd+ first moves the folder of completed files to this location and then unpacks it. This results in the script labeling the unpack folder grey, and after the unpacking is finished it labels the file but it doesn’t hide the extension. It does when i move a file myself.

The guy didn’t have enough knowledge of Applescript to further expand this script, and my own skills don’t go further than opening the application. So i end up here.

I hope i explained it well and that someone is able to help me.

Thanks,

Folder Actions are not as reliable as they might be if the folder is flooded with files. I have a couple of questions, however.

  1. Is the input to this folder loose files, files in folders, or both?

  2. Are their any files in this folder that have already been viewed and then had their label changed back? That appears to be the case from your image.

  3. Does each unpacked folder contain only one file?

I think there are better approaches to this, but need more info first.

SABnzbd+ moves a “_UNPACK_Show - S01E01 - Episode Name” folder filled with .rar files to the folder, unpacks the contents, renames the file, moves the unpacked file from it’s folder to it’s parent folder (“Lost (Season 6)”) and deletes the folder with the .rar files.

Sometimes the .rar archive contains more files, like .nfo’s, images and links but SABnzbd+ also removes them and keeps only the video file.

On rare occasions i move a file there myself when SABnzbd+ has made a mistake.

So the input to the folder is files and folders, but the ultimate result is always just files.

To answer your other question:
In the screenshot i labeled two files correctly and the last one incorrect just to show what i meant, i have already watched these three episodes. So yes, i did change the label back.

But what i think you want this info for is to automatically label files that have never been opened, this would not be the best solution since i can’t open the files to check the quality anymore unless it will not remove the label. (That’s fine btw, i can remove the label manually).

Anyone? :rolleyes:

:confused:

Hi,
Since I never use folder actions, I suggest using an idle-handler with a property that contains all files who are already processed. I didn’t try this script so it could be there are some bugs in it, but I think you’re smart enough to solve them yourself :). (if there are any).

Goeiendag,
Ik zelf gebruik nooit map-acties, dus ik stel voor om een idle-handler op te zetten. In het script is er ook een property die de reeds gelabelde bestanden opslaat, zelfs nadat het programma stopt. Ik heb het script zelf niet getest dus het zou kunnen dat er hier en daar een foutje in zit, maar ik denk dat je zelf wel slim genoeg bent om het op te lossen. Als er al zijn.

Save the script as a stay-open application. If you want you can add the application to the login-items and make the application’s icon stay out of the dock. (Google is your friend)

Script:

-- PROPERTIES
property MAIN_FOLDER : missing value

-- VALUES
property COLOR_LABEL : 7 --gray
property IDLE_DELAY : 30

-- SCRIPT STORAGE
script o
	property p : {} --processed files
end script

on run
	-- folder exists
	set MAIN_FOLDER to checkValidFolder(MAIN_FOLDER)
end run

on idle
	main(MAIN_FOLDER)
	
	return IDLE_DELAYS
end idle

(* ===== HANDLERS ====== *)
on main(aFolder)
	set folderPosix to (POSIX path of aFolder)
	if folderPosix does not end with "/" then set folderPosix to (folderPosix & "/") as string
	set folderContents to list folder aFolder
	
	repeat with i in folderContents
		set itemPosix to (folderPosix & i) as string
		set itemHSF to alias (POSIX file itemPosix)
		
		-- if file, not hidden and not already processed
		if (o's p) does not contain itemHSF and (folder of (info for itemHSF)) is false and (visible of (info for itemHSF)) is true then
			tell application "Finder"
				set label of itemHSF to COLOR_LABEL
				set extension hidden of itemHSF to true
			end tell
			set end of o's p to itemHSF
		end if
		
		-- if folder recursive
		if (folder of (info for HSF)) is true then
			main(itemHSF)
		end if
	end repeat
end main

on checkValidFolder(f)
	if f is missing value or f is "" then
		set f to (choose folder with prompt "Kies de map met de films.")
		return f
	end if
	
	try
		set f to f as alias
	on error
		set f to (choose file with prompt "De map \"" & (POSIX path of f) & "\" bestaat niet. Kies een andere.")
	end try
	
	return f
end checkValidFolder

Hope it works,
ief2

PS: Groeten uit België!!