My Solution to file organization

Discussion in 'Mac Apps and Mac App Store' started by armandocerna, Nov 19, 2004.

  1. armandocerna macrumors regular

    Sep 22, 2004
    Chico, CA
    I use my ibook all day long at work at home at school, for everything. All of my documents started getting messy in the Documents folder. It was my place to kind of throw everything. So after reading this article I decided to do something about it becuase the mess in my documents folder was kind of bothering me. Being a long time linux user I decided the best approach to this would be just to do what I know. So I wrote the following little simple bash script:

    cd ~/Documents
    mv *.doc Office\ Documents/
    mv *.ppt Office\ Documents/
    mv *.xls Office\ Documents/
    mv *.pdf PDF\'s/
    mv *.jpg Images/
    mv *.ai Images/
    mv *.psd Images/
    mv *.png Images/
    mv *.tif Images/
    mv *.ooutline Outlines/
    mv *.* Other/
    All of these directories I created before writing the script my initial plan was just to move stuff around. So I made my little script executable and created a cron job for it to run every minute. Now all I have to do is save my stuff into my Documents folder and it gets organized very neatly into the correct folders a minute later.
    I also thought what if I save something to my documents folder and it gets moved over but I am still working on it. Even if this were the case though what ends up happening is that it just moves the newer saved copy over the otherone and overwrites everything. After I did this I dropped a few more files into the documents folder and it worked perfectly. I just want to take some time now to layout the steps so that anyone could do it.

    1. Decide your directory structure
    2. Create any folders you want in your documents folder
    3. Open your favorite text editor and copy my above script into it making any changes you feel are necessary, adding extensions etc.
    4. Save it where ever you want I chose to save it under the name in a directory called "Scripts" I made in my home directory.
    5. open a terminal
    6. type "cd ~/Scripts"
    7. type "chmod +x" this will make the file executable so that you can run it from a cronjob
    8. type "./" to do a test run on your script it should now be moving all of your documents around and the changes should reflect in the finder.
    9. If you like the desired results type and wish to automate it to run every x minutes. Edit your user crontab by typing "crontab -e"
    10. In my case I had one line in this file that ipodderx uses to automatically grab streams from podcasting feeds you will probably just see an empty window with a bunch of ~'s in it.
    11. Hit the "i" key this will allow you to insert text in the vi editor.
    12. Paste the following line into the terminal: */1 * * * * ~/Scripts/
    13. This will automatically run the relocate script every 1 minute. You can change 1 to whatever interval you wish.
    14. Enjoy having an organized Documents folder.

    If anyone has any feedback on my little solution for a messy documents folder or any improvments for my script please respond. Good luck.

  2. broken_keyboard macrumors 65816


    Apr 19, 2004
    Secret Moon base
    I like it. It is the Unix style to solve problems using new combinations of existing tools, instead of creating a custom solution each time.
  3. BeoVir macrumors member

    Jun 3, 2004
    Detroit, MI
    That is very cool for moving documents that I create but what about those annoying applications that assume you want their data files in your documents folder! Can I move those without breaking the applications?
    For example...
    microsoft user data, virtual pc lists, virtual pc scripts, appleworks user data, etc. I hate having applications use documents like their own personnal dumping grounds!
  4. armandocerna thread starter macrumors regular

    Sep 22, 2004
    Chico, CA
    I have it setup to move only files so I left my Microsoft directory where it is. The mv *.* will only moves files. So you can just setup your stuff the way you want it and maybe modify the script a little bit.
  5. Baron58 macrumors 6502

    Feb 19, 2004

    An improvement for No. 8, and a caveat for No. 9:

    If you were to name it 'relocator.command' and chmod it to be executable, it then becomes double-clickable in the Finder (at least under 10.3.x, and I believe under 10.2.x as well).

    The problem I see with doing it automatically is what if you open a file from other than the 'approved' folder, and then the cron'd script automagically jerks it out from under you and files it. Sure way to lose data and corrupt that file. Plus, you want to make sure it's YOUR crontab, not the root/system crontab (/etc/crontab) or else the command will run as root, not as you.

    Instead of using to simple mv *.* you should make it more sophisticated by doing:

    mv `find $HOME/Documents -maxdepth 1 -type f -iname "*.doc" | grep -v "$HOME/Documents\."` $HOME/Documents/Office\ Documents/

    Note - those are BACKTICKS not apostrophes/single quotes around the find comand.

    This would exclude files starting with a ".", ignore directories, and stay within the specified folder.
  6. armandocerna thread starter macrumors regular

    Sep 22, 2004
    Chico, CA
    I thought that would be a potential problem but everything buffers a copy of the file so it's not like you loose what you are working on. The mac is smart enough to handle it. Try it out.
  7. Baron58 macrumors 6502

    Feb 19, 2004

    No, 'everything' doesn't.

    Also, there are some apps (e.g. ArchiCAD) which internally flag items as being in-use in addition to normal flock() filesystem calls. Trust me, you don't want to d*ck around with moving open files.

Share This Page