Applescript Monday: Make a Clear Desktop Script

by Clay Moore on March 15, 2010

in AppleScript Mondays,Computer Language,programming

Often times with programming training it takes for ever for the course to get somewhere where we can do something practical. That’s why I like to do something practical, as soon as possible. So with what we know so far what can we do? I think we need a script to clear our desktop of all the files that collect there. So. after the break, we will make a clear desktop script.

There’s a couple of Applescript concepts I want to introduce. The first is object types. These are the words in Applescript that are the large type words like file and folder. File and folder in Applescript represent all the files and all the folders. All files in any folder can be considered to be generic files. The same can be said of the generic object folder which represents all folders.

The next concept is that of enumerations. Enumerations are words that represent quantities. Right now I am interested in the word that represent all of something. In Applescript this word is every. If I want to work with all the files or folders I use every in front of the object type. To select all files I would use the phrase every file or every folder.

Now I need the verb that will move the files from the desktop to a folder of my choice. I could probably guess it, but last week I showed you how to find the verbs that an app exposes to Applescript. So, Startup Applescript editor and take a gander at the Finder dictionary. This is the link to the post which showed you how to do that. Look inside the standard suite for the command. Looks like move is the verb I want.

Screenshot2010-03-14at5.51.25PM.MLIKu65jvFJD.jpg

So our command is “move every file.” That’s still not enough we have to have a from and a to. We can use the prepositional phrase “of whatever” To indicate our from. We are moving from Desktop to some other location. The other location needs to be in your user’s folder, the one with your user’s name on it. Create a folder there called From Desktop. We now have our destination.

The full phrase looks something like “move every file of desktop to the folder “From Desktop” of home.” Notice that we used words like Desktop and home. These are the actual containers we are using. Desktop is that screen, and home is the folder with your name on it. Since we also want to make this script work with the folders we will need a second command to work on the folders in the desktop. Fortunately it is the same command as for the files but with the word folders instead of files.

Screenshot2010-03-14at5.36.52PM.uBB2M0tZnBBj.jpg

Because we want the Finder to execute the commands we will tell the Finder to do it. And both command inside of the tell block. Like the screen shot above.

Next week we will make the above script even more useful. Try this out and then go to Library>>Scripts and save this script there as Clear Desktop. That command should appear in the general script menu. Now you can use it all the time.

  • Share/Bookmark

Related posts:

  1. AppleScript Mondays: Extending the Clear Desktop Script
  2. AppleScript Mondays: Let’s Open a dictionary
  3. Very Basic AppleScript
  4. Using DevonThink as a Super Finder
  5. My writing workflow

Leave a Comment

{ 2 trackbacks }

Previous post:

Next post:

<