The Removing of an Extension 4

Home

What's new?

Help

Plug-ins

Plug-in Tutorial

  1. introduction
  2. talking to AEP
  3. processing
  4. making it better
  5. another removal
  6. add an extension
  7. some tips

Download

Doing more, with less

As a way to get you to look at the rest of the template, lets do one more plug-in for removing file extensions, but this time with a twist. Have you ever noticed that certain decompressing applications will run Disk Copy when they have extracted an image? I like AEP to behave the same way, and making a plug-in that does that is terribly easy.

First make a fresh copy of the plug-in template for removing file extensions and name it something like Disk Copy. As you might know, disk images have file extensions like dimg, dImg, dmg, img and smi. (Actually there are a few more, but lets leave it at that.) Now is your chance to prove what you've learned. Why don't you fill in the WhatDoYouHandle routine of the new plug-in. No peeking until you have tried!

Did yours look anything like mine? If it did, well done, if not, don't worry, there's another chance coming up.

The next order of business is filling in the application name and creator code. Remember to use the Get creator code application in the template folder. (Just skip past the definition of the error codes.)

So far, we have just repeated what we did before. Now we will go on. I won't go into many details, just pointing out some interesting things along the way.

The next piece of code uses the items you supplied to check if it can find the application you want. If there is a problem, it will let the user know and bail out. As you can see, it places the file back in its original container and tells AEP not to worry about anything else, using an error code defined at the beginning of the function.

After this the plug-in saves some more information into variables like the name of temporary folder, the name of the current item and the extension that the user removed. It then uses this information to guess what the name of the new file will be when the extension is removed. Finally, it does another error check by making sure that the name of the current item ends with the extension the plug-in is supposed to remove. If it doesn't, the plug-in is in the wrong folder and it warns the user.

In the next bit of code, the plug-in tries to estimate how long the helper application will be working on the current item. This is necessary, because Applescript will generate an error if it has to wait too long for an application to finish doing its job.

Now we get to the part were the plug-in tells the helper application to do its stuff. When you use a drag-and-drop application, it is enough just to tell the helper application to open the specific file. (As you can see, the plug-in tells Applescript to wait for the time it just calculated before generating an error message that the operation went on too long.)
After this it tells the application to quit. This command is enclosed in a special section that tells Applescript not to wait for the helper application to confirm it has quit. Most applications don't tell Applescript this, so Applescript will send the command again. Usually the application has already quit, but as it is send an Applescript command, it will start up again, and following the command quit, not telling Applescript it did. So Applescript will tell it to quit again and so on, until Applescript feels it has waited long enough and generates an error message.

As we near the end of the plug-in we also get to the point were you might wish to wake up, because you need to do something. When the helper application is done, the plug-in tries to find the item that has been created by the helper application by looking in the temporary folder for a file with the name of the original file minus the file extension. If it finds this, it will return this item, otherwise it will tell AEP it couldn't find the item so AEP can try.

When you open a disk image, Disk Copy doesn't change the name of the image file. If you leave the code like this, neither the plug-in nor AEP will find the new file and AEP will generate an error message. To rectify this situation, you just have to tell AEP to use the original item. Begin by deleting the portion in the above code between try and on error.
When you've done that, you just need to type return CurrentItem between those lines. The resulting code should look something like this.

Save the new plug-in, drop it into the appropriate folder and you're done. That's two new plug-ins done all ready, and also gone through the entire basic structure of an AEP plug-in! I think you deserve a nice cup of tea or something, before continuing with the fifth part of this tutorial.


A.E.P. The Active Extension Processor - Created by Roger Jolly - Copyright 2002 - All rights reserved.