I only found one problem with the code that kept it from running on my box. The problem is not in the actual opening of the drawer, but is actually quite a few lines above where you’re trying to reset the values of and then close the drawer. You must execute this in a try statement so if the drawer is closed already it won’t try to force closing it again. Other than that, all of the other code seems to be working. It’s format was automatically updated to 10.3-compatible when I opened it, so there may have been some changes made that I didn’t consciously make. I’m pretty sure adding a try statement will solve it, though. Once you get a final version, if you need a rebuild for 10.3 just send me another copy and I’ll build it again and send it back.
Just some design notes…
You might want to open the drawer AFTER setting the values in the fields and the picture. It makes the opening transition go a lot smoother.
You should consider using some other, less common delimiter for your databases. A common delim for flat-file databases is the pipe " | " symbol. It’s rarely used and most likely won’t get entered by a user as part of everyday typing. A comma could easily get entered and would screw up your entire database file structure.
You also should get in the habit of setting applescript’s text item delimiters back to the values they were at before you changed them. This will help you avoid any conflicts later down the code. Applescript uses it’s delim’s to create lists and make strings from lists, so if they’re set wrong, you may end up with unpleasant and difficult to troubleshoot problems.
To reduce the risk of memory pile-up, I prefer to set my permanent images as variables on launch, and then to release any images I load during use as they are no longer needed. See sample below.
Here’s the updated problematic code…
try --> Add this!!
tell drawer "item"
set the contents of text field "template" to ""
set the contents of text field "sku" to ""
set the contents of text field "engraving" to ""
set the contents of text field "producingplant" to ""
set the contents of text field "vendor" to ""
set the image of image view "preview" to load image "no image"
close drawer
end tell
end try [b]--> Add this, too!
Sample of resetting the delimiters…
set DelimOld to applescript's text item delimiters --> Save the old delim
set applescript's text item delimiters to "|"
--> Do something
set applescript's text item delimiters to DelimOld --> Revert to the old delim
Pre-loading and Releasing images
(* Preload an image, *)
property NoImage : missing value
on launched theObject
set NoImage to load image "NoImage"
end launched
--> Usage --> set image of image view "imageView" of window "mainWindow" to NoImage
(* Set new image and release old *)
try
set oldImage to image of image view "imageView" of window "mainWindow"
end try
set image of image view "imageView" of window "mainWindow" to load image "newImage"
try
delete oldImage
end try
Keep it going. Your work is functional and practical…as it should be. Nice job on the icon, too. Let me know if there are any more troubles.
j