is there a way to create an applescript to auto-label files in a specific folder?

Discussion in 'Mac Programming' started by steezy1337, Sep 11, 2011.

  1. steezy1337 macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #1
    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?
     
  2. DESNOS, Sep 12, 2011
    Last edited: Sep 13, 2011

    DESNOS macrumors 6502

    Joined:
    Aug 24, 2011
    #2
    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.
     

    Attached Files:

  3. steezy1337 thread starter macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #3
    Thanks for that I'll give it a go when I get back in my mac, to add more options do I just add more of the if curlext?
     
  4. steezy1337 thread starter macrumors 6502

    Joined:
    Dec 29, 2008
    Location:
    Carlisle, UK
    #4
    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.)
     

Share This Page