Plug-in Tutorial
|
Doing more, with lessAs 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
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.)
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 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.
|