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

elbirth

macrumors 65816
Original poster
Jan 19, 2006
1,154
0
North Carolina, US
I'm trying to help someone work around a problem they're having. They use Pandora at work on an iBook, and because Pandora caches the songs it plays, their hard drive gets filled up after a while and runs out of disk space (not a whole lot of space free to begin with).
We've tried changing the cache size settings in multiple browsers, but they don't seem to stick.

My thought was to write up a simple script that you could run (maybe run it through iCal at specific intervals?) that would empty out the cache folder at a specified interval. The person I'm helping has no scripting knowledge at all, and while I kind of do, I don't know how to do this (or if it's possible).

Does anyone have any ideas?
 
it's a pretty simple script you need the path of the folder you are trying to empty. First to test it works try the following script which will move the files to a test folder (called testdump) on the desktop

Code:
try
          do shell script ("mkdir ~/Desktop/testDump")
end try
do shell script ("mv \"/unix/style/path/to/the/folder/you/are/deleting/*\" ~/Desktop/testDump")
the final /* needs to stay.
once you get this working then create the following applescript
Code:
do shell script ("rm \"/unix/style/path/to/the/folder/you/are/deleting/*\")
then you can save this script and schedule it from an iCal event as an alarm. Please make sure the script is moving the files to the testdump folder before deleting them directly to make sure you are deleting the correct files.

To find the UNIX style path you need get info on the folder containing the pandora files.
 
that works perfectly so far, thanks! one other thing though, since I know it works right, how would I go about emptying the trash? would something like this work, or would it need to be set up differently? (I'd rather ask before deleting something important on accident)

Code:
do shell script ("mv \"Users/username/Library/Caches/Firefox/*\" /Users/username/.Trash")
do shell script ("cd /Users/username/.Trash")
do shell script ("sudo rm -ri /Users/username/.Trash/filetodelete")
 
Instead of messing around with iCal alarms I would just create a shell script. Save the following code somewhere (your home directory for example).

Code:
#!/bin/sh
rm -rf /path/to/files/*

Then execute this to make it executable:

Code:
sudo chmod +x ~/myscript

Then use cron to execute this script whenever you want. Just type "crontab -e" in a Terminal and paste the following line into the editor - then just save and voila.

Code:
# m h  dom mon dow   command                                                                                            
*/15 * * * * ~/myscript

This tells cron to execute your script every day of the week every 15 minutes. Change the 15 to 30 for every half hour, etc. If you want to execute it every hour then change the "*/15 *" to "* */1" instead.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.