Script only to run when files are no longer present in the folder

Hi guys

I use speed download to download to a specific folder on my mac. When speed download is downloading files, it adds the extension “.partial” to the filename, and then corrects the filename once the file is completly downloaded. I am currently using Hazel to help me unzip these files and move them to the correct folders. However, i only want Hazel to activate the unzip rule or any other rule ONLY when there are NO .partial files in my folder.

Can anyone suggest a script that perhaps, turns the files (no folders…as there are 2 subfolders in this directory) to green only when there are no partial files in the folder. And then that way, i can then have Hazel process these green files with specific rules.

Thanks alot
Chris

Feel free to add of remove filetypes. I use this for my downloads folder. Just add it as a folder action by copying it into your /Library/Scripts/Folder Actions Folder, then activate it on the folder you want it to work on…

http://macs.about.com/od/diyguidesprojects/qt/addfolderaction.htm for info on folder actions.


on adding folder items to this_folder after receiving these_items
  set fileColorList to {oranges:{"mpg", "mpeg", "bmp", "wma", "c", "cpp", "dmg", "doc"}, reds:{"asf", "jpg", "jpeg", "ram", "h", "hpp", "mpkg", "iso", "bin", "ppt", "pps"}, yellows:{"mov", "qt", "gif", "aif", "aiff", "htm", "html", "hqx", "tar", "xls"}, greens:{"mp4", "rgb", "rgba", "pcm", "js", "css", "cgi", "pkg", "gz", "z", "tgz", "pdf"}, blues:{"avi", "tif", "tiff", "mp3", "m", "zip", "eps", "ai"}, purples:{"wmv", "png", "wav", "scpt", "tbz", "bz2", "dat", "txt", "prefs"}, greys:{"rm", "ram", "ra", "psd", "pl", "xml", "plist", "sit", "rar", "rtf", "rtfd", "torrent"}}
  
  tell application "Finder"
    
    repeat with myFile in these_items
      --display dialog myFile as string
      if the name extension of myFile is in oranges of fileColorList then
        set label index of myFile to 1
      else if the name extension of myFile is in reds of fileColorList then
        set label index of myFile to 2
      else if the name extension of myFile is in yellows of fileColorList then
        set label index of myFile to 3
      else if the name extension of myFile is in blues of fileColorList then
        set label index of myFile to 4
      else if the name extension of myFile is in purples of fileColorList then
        set label index of myFile to 5
      else if the name extension of myFile is in greens of fileColorList then
        set label index of myFile to 6
      else if the name extension of myFile is in greys of fileColorList then
        set label index of myFile to 7
      end if
      
    end repeat
  end tell
end adding folder items to


In your case, you could color the .partial files red (don’t activate), and then when they get renamed to .whatever, the folder action will re-color it to green. You can then have have hazel watch for that color and perform the action.

When a file extension is changed, ‘on adding folder items’ won’t get triggered only when the file is added to the folder.

I am not at a computer to test this, but my understanding of the ‘on adding’ trigger : it won’t trigger if the file ‘contents’ are modified (like re-saving a text file after editing,) but since the file NAME is changing, it should be tripped as a new file ‘added’.
New name = new file for this watcher.

You’re right i’m wrong :smiley:

Hello

this one may help :



on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder "for_Hazel" of this_folder) then make new folder at this_folder with properties {name:"for_Hazel"}
		set hazel_folder to folder "for_Hazel" of this_folder as alias
		repeat with myFile in these_items
			if the name of myFile does not end with ".partial" then
				move myFile to hazel_folder
			end if
		end repeat
	end tell
end adding folder items to


It would move every added file whose name doesn’t end with “.partial” in the subfolder “for_Hazel”
You will just have to ask Hazel to treat this folder.

Yvan KOENIG (VALLAURIS, France) samedi 18 février 2012 22:06:16