måndag, september 10, 2012

Folder action script

I'm following a bunch of tv series which I download. The problem I was facing was to remember which episode I last viewed. I could always keep the last episode on my computer of course. But that soon took up to my disk space. Specially when the season had ended and it took another half year until next episode.

So I started to investigate what Mac OS X's Folder Actions was. 
It's action based on happenings in a specified folder. You apply a script to it and it does the rest. 

I'm having this script attached to a folder i call SEEN which I put all the watched episodes in when I'm done.

The script:


on adding folder items to this_folder after receiving these_items
 
 set dialogResult to display dialog "Empty content of file(s)? No way to undo!"
 
 if button returned of dialogResult is "OK" then
  
  repeat with i from 1 to number of items in these_items
   set this_item to item i of these_items
   
   do shell script ("cat /dev/null > " & quoted form of POSIX path of this_item)
   
  end repeat
  
  display dialog "Done."
 end if
 
end adding folder items to




So when I'm done watching an episode, I put it in my SEEN folder and a questions popups asking me if I want to empty the file. I click OK and voila, the file is 0 bytes.