How can I automaticly move every file on desktop to specific folder based on extension?

I'm looking for something, probably some kind of action script, that will at any time move everything that's on my desktop directly to a specific folder on my desktop, based on the extension. Just to prevent cluttering.

Some examples I want:

  • Folders: Do not move
  • .PSD/.Ai/.INDD (all Adobe workfiles) -> Move to -> ~/Desktop/Workfiles
  • .PNG/.JPG (etc., All picture files) -> Move to -> ~/Desktop/Pictures
  • .doc(x)/.xls/.pdf (all document files) -> Move to -> ~/Desktop/Documents

Others I guess I can do myself based on the how-to for above.

I hope someone could help me with this! Any action script/Mac functionality/3rd party app (free/paid) that does this is acceptable, with the only minimum requirement the check and move of files must be directly/every 30 mins (at max)

Thanks!


Solution 1:

You can do this in the terminal (shell). Open the terminal and type cd ~/Desktop to change you current working directory to the Desktop.

Then for the different cases you listed:

mv *.PSD *.Ai *.INDD ~/Desktop/Workfiles

mv *.PNG *.JPG ~/Desktop/Pictures

mv *.doc *docx *.xls *.pdf ~/Desktop/Documents

mv file target is the command to move files. You can move multiple files at once: mv file1 file2 file3 target. The asterisk * is the so-called wild card character. So * stands for every character or character sequence. *.doc would mean that it would affect all files that end with .doc. You could also do it other way around, e.g., A* to affect all files that start with A.

If you want, you can copy the following lines into an empty text file and save it as example.sh and add #!/bin/bash to the first line. Make it executable by typing chmod ugo+x example.sh. Then, you can use it every time you want to move your files from your desktop by typing ./example.sh in the shell from your desktop.

So the suggested script contents would could look like this:

#!/bin/bash

cd ~/Desktop

mv *.PSD *.Ai *.INDD ~/Desktop/Workfiles
mv *.PNG *.JPG ~/Desktop/Pictures
mv *.doc *docx *.xls *.pdf ~/Desktop/Documents

As mentioned in the comments, you can save it as example.command and use chmod ugo+x to make it clickable and executable

Solution 2:

In Automator do following, Open Automator and select "Services"

Than recreate this for your images files.

Let me know if you have problem.

Save this "Service" and give it a name like "Move images from desktop"

enter image description here

In Finder only select the one(s) on your desktop you want to move, and under Finder select Services and than you will see your service you just made, so select it.

Now every time you want to clean your desktop just to the above. If you want it even faster, you can assign a keyboard short cut for it.

Solution 3:

Hazel is what you want.

It's like Mail.app rules or Gmail filters, except for your files.

Here's an example rule that will do what you're looking for in the first set

It costs $25. It's worth that much and more. If you value your time at $5/hour this app will pay for itself and increase your satisfaction with your Mac usage.

It's basically a servant in app form. :-)

There's a 14-day free trial, and the developer is extremely responsive. Your money will go to help support a great Mac app that does something incredibly well. Actually, it does lots of things incredibly well.

(Note: I have absolutely no connection to this app or its developer except being a huge fan.)

Yes, you could write your own shell script or AppleScript to do this with launchd. I could do it faster than you could, because I've done it before. But I bought Hazel. Why? Because it's the best solution. And once you start using it, you will find so many different uses for it, you'll be glad to have it.

Seriously I can't use a Mac without this anymore.

What you can search for:

Here are the "attributes" you can search for:

("Kind" is thing like "image" or "document" or "folder".)

You can setup multiple criteria per folder, and you can set the precedence as to which rules run in which order.

What you can do for matching files:

Here are the actions that you can take on a file which matches those attributes:

Download the demo and start using it, and in two weeks I bet you won't want to give it up.

Examples

Here are some things that I do with Hazel:

  1. When a new .zip arrives in my ~/Downloads/ folder, I automatically open it with The Unarchiver which unzips it to ~/Actions/Unzip/

  2. Hazel looks in ~/Actions/Unzip/ for files which end with .app and if it finds any, it moves them to /Applications/

  3. .pkg files? Hazel opens the Installer app

  4. .dmg? Hazel mounts it

  5. .pdf? Hazel moves it to ~/Dropbox/Documents/Downloads/ and then opens it

  6. Image? Hazel moves it to ~/Dropbox/Photos/

  7. New .amz file in ~/Downloads/? Hazel moves it to ~/Music/ and then runs clamz on the file

  8. new PDF in ~/Actions/OCR/? Hazel opens it in ABBYY FineReader

  9. New file in ~/Actions/ToAir/? Hazel will scp the file/folder to my MacBook Air from my iMac and then move the file to another folder when it is done. (Ditto on my MacBook Air if if put a file into ~/Actions/ToiMac/)

  10. I have Drafts setup on my iOS devices setup to save snippets as text files in specific folders to trigger actions on my remote Macs. For example, any new text file in: ~/Dropbox/wget/ gets processed with wget so I can download files from my iOS devices to my Dropbox.