Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

steezy1337

macrumors 6502
Original poster
Dec 29, 2008
338
0
Carlisle, UK
as the title says really, i'm wanting to find a way that i could create an applescript that would watch my downloads folder and then label different file types with the appropriate colour (red for PDF's, blue for .dmg's etc). i tried just using a smart folder but this collated all the files on the whole computer that matched the chosen file type. does anyone know how i'd do this or point me in the right direction?
 
Code:
property oldFiles : missing value
on idle
	tell application "Finder"
		set curFolder to ((home) as string) & "Downloads"
		set curFiles to files of folder curFolder
		if curFiles is not equal to oldFiles then
			repeat with labelFile in curFiles
				tell application "System Events" to set curExt to (name extension of file (labelFile as string))
				-- 1 is orange, 2 is red, 3 is yellow, 4 is blue, 5 is purple, 6 is green, 7 is grey (Different order from the one showed in the finder)
				if curExt is equal to "pdf" then
					set label index of labelFile to 2
				end if
				if curExt is equal to "dmg" then
					set label index of labelFile to 4
				end if
			end repeat
			set oldFiles to curFiles
		end if
	end tell
	return 30
end idle
There you go. Save this as a "stay open" app, and it'll only run if the file names in the downloads folder change in any way. I do it this way rather than a folder action script because folder action scripts don't respond to file renaming, which occurs when a safari download completes, making it unreliable. You can also just download the attached file. It should work.
 

Attachments

  • LabelFiles.app.zip
    24.5 KB · Views: 97
Last edited:
just to avoid making a new thread, i've got the applescript working great but i'd like it to be able to move the files to specific locations based on the labels it's given to the files (move blue labels to Install files folder, red to PDF folder etc.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.