AppleScript for labeling folders.

Discussion in 'Mac Programming' started by ProB4ProTools, Mar 3, 2010.

  1. ProB4ProTools macrumors newbie

    Mar 3, 2010
    Hey All,

    I'm trying to create a simple script that will go through the folders of a directory and label any folder that does not contain a .wav file. This directory has thousands of folders that should all contain .wav files but for me to double check I would have to scroll through all of them manually. I've tried putting together a script using some random google results but all I've gotten it to do is label the actual wav file, if it exists - that's not helpful at all, lol.

    Thanks in advance!
  2. Willi Gofarr macrumors newbie

    Nov 30, 2009
    London and New York
    Not sure about the AppleScript equivalent, but

    find . \! -name "*.wav" -print
    will work in Terminal to quickly flag any non wav files, if that's a help.
  3. ProB4ProTools thread starter macrumors newbie

    Mar 3, 2010
    There are other files in those folders along with the .wav so that isn't exactly going to do it, thanks though! Every folder in the directory should contain pdf, jpg, and wav files. There are thousands of folders and I want to make sure that all of them contain atleast one wav file. Having a script that applies the built in color labels to point out any problem folders is ideal. This way I can quickly scroll through the directory and locate any problems.
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Do you need to label only the specific folder that's missing a .wav file, or do you need to also label its parent folder and so on up the parent-folder chain?

    Would you be willing to accept a compromise, which created a special sentinel file named "no-waves-here" in folders that are missing a .wav file? That seems like something the 'find' command could do as a single command.

    Then to get the list of all such folders, I'd tell Finder to find all the occurrences of "no-waves-here" and show it in a Find window (which could then be saved as a Smart Folder). You can do what you want with the folders at that point.

    A shell command using 'find' to delete the "no-waves-here" sentinels would also be easy to do. Or you could trash them from the Find window.

    The above all seem like things you can get Automator to do as steps in a workflow.

    This breaks the problem down into a series of simpler steps that are easier to do individually. If you were going to repeat this task many times, it'd be worth doing a complete end-to-end script for. If it's single-use, then simpler steps with a little manual intervention are, well, simpler.

    Also, what would you do with the labeled folders? Maybe that can be one of the simpler steps, too.
  5. ProB4ProTools thread starter macrumors newbie

    Mar 3, 2010
    chown33, thx for the detailed response!

    I need to label just the one specific folder that is missing the .wav file. There would be just one parent folder so there would be no need to label anything above that.

    The "no-waves-here" method you described can definitely be an option but I'm fairly new to Automator and AppleScript so I'll have to play around a bit.

    This process would be run on a few different archives which can add up to about 30,000 folders so an automated script would be ideal. I'd also like to run it occasionally just to do a checkup on things.

    I just need those folders labeled to take a deeper look into why there is no wav file there. No deletion or move is necessary.

    Thanks again for all the help!
  6. mysterytramp macrumors 65816


    Jul 17, 2008
    I did a very limited test and this seemed to work:

    tell application "Finder"
    	set theFolderList to folders of (choose folder)
    	repeat with fl in theFolderList
    		set fileList to (every file of fl whose name extension is "wav")
    		if fileList is {} then
    			set label index of fl to 3
    		end if
    	end repeat
    end tell
  7. ProB4ProTools thread starter macrumors newbie

    Mar 3, 2010
    mysterytramp, that script works like a charm! Thanks so much! I'm fairly new to AppleScript so I'm picking it apart figuring out exactly what each line of code is doing. Great learning experience!

Share This Page