Just wondering if anyone out there in MacScripter Land can help me with this…
I have created an Applescript application (in Xcode) that is doing its job. However, I want to add the ability to drag text files onto the application’s icon in the finder and have the application open the file.
Is there a way to add this ability to my current application, or do I have to go back and re-create the entire program in Xcode using the 'Applescript Droplet" project type when I first create the project?
Have you taken a look at the sample code provided in “Drag and Drop” located in the AppleScript Studio examples folder installed by the Developers tools? This should get you going. Remember to link the “open” handler to the File’s Owner resource in IB for the event to be passed correctly.
On another tangential note, I have an “on open” handler in my script linked to the application and it indeed works from the Finder or the Dock but only when Command-Option are held down during the drop. If I don’t hold these down, the icon never highlights indicating it can receive the drop. If I do hold down Command-Option, it works as expected. Can anyone offer some insight on this?
Thanks for the info, Jon. I’ve added a the document types to my target, and the built app now accepts dragged files.
I can’t, however, get the file to open in the app. Can you provide some info on how to, as you say, “link the “open” handler to the File’s Owner resource in IB for the event to be passed correctly.”
Open your MainMenu.nib (or whatever the main NIB is called) in IB, click on the File’s Owner icon in the MainMenu.nib Instances tab, from the Info palette select AppleScript, click on the disclosure triangle on the Application section of the Event Handlers view, and make sure the “open” handler is checked and linked to the main AppleScript. Be careful, however, that changing this may cause the File’s Owner’s handlers to be called after the awake from nib handlers of other NIB elements. This isn’t a problem unless your app initialized values on the “will finish launching” handler that need to be initialized before windows or other elements are loaded from the NIB.