Last week we discussed making a clear desktop script to move files to a folder in our home directory. There are a few things I want to add and something I wish to remove from that script. So, after the break I’m going to show how you can make the destination folder and test to see if it already exists.
If you made this script the last time and put it in the Script folder of the System Library folder, then you need to open the Applescript editor, and open the Clear Desktop script file with the editor.
The First thing I want to do is to remove the move every folder element from the script. When I work I put files on the desktop not folders. so I only want to clear files off of my desktop. The second thing I want to do is make sure that the folder exists by creating it. They way I work is I use the From Desktop Folder to hold my work. The folder’s existence tells me that I did not move the files to their final destination, if any. When I do process the files I delete this folder to tell me that I did that.
So, to create the folder I use the make verb along with a specifier telling the finder what exactly to make. It looks something like this “make new folder at home.” That’s great but we need to give the folder a name, which happens to be a property we can specify properties with the with property preposition and a list of properties, which are name:value pairs. So the property would look like {name:”From Desktop”}. This is placed after the with prepositional phrase.
We can’t always depend on the folder not being there, and the Finder gets confused with two things with the exact same name try to exist at the same location. So we need to not make the folder when it exists. We do this by encasing the entire make new phrase in an if block. This if block only makes the folder if it does not exist. The entire script is in the screen shot below.

Save the script as it now is. Now you have a moe robust script that can handle if the folder does or does not exist at the location.
Related posts:
{ 1 trackback }