Xcode droplet crashes

I’ve been trying to write an applescript droplet with XCode, and it keeps crashing. I don’t think my code is buggy (it is very simple). All that is necessary is to create a new applescript droplet (New Project… → applescript droplet) and replace “on open names” with the following code:

on open names
	do shell script "ls"
         --or any shell script command will do
end open

Build it, then drag any file to the application. I get an application crash. Does anyone else experience this, or is there something wrong with my setup?

For information, the backtrace is:

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
0 <<00000000>> 0x00000000 0 + 0
1 com.apple.AppleScriptKit 0x7f776f88 -[ASKApplicationOpenEventHandler handleAppleEvent:withReplyEvent:] + 0x7c
2 com.apple.Foundation 0x90a4a9d0 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 0x164
3 com.apple.Foundation 0x90a510b4 _NSAppleEventManagerGenericHandler + 0x78
4 com.apple.AE 0x91674a68 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned long, unsigned char*) + 0xd0
5 com.apple.AE 0x916778b0 dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 0x2c
6 com.apple.AE 0x91674ca8 aeProcessAppleEvent + 0x11c
7 com.apple.HIToolbox 0x928c47bc AEProcessAppleEvent + 0x3c
8 com.apple.AppKit 0x92dd2790 _DPSNextEvent + 0x358
9 com.apple.AppKit 0x92de8f34 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 0x74
10 com.apple.AppKit 0x92dfd27c -[NSApplication run] + 0x21c
11 com.apple.AppKit 0x92eb95f0 NSApplicationMain + 0x1d0
12 ??? 0x00009164 main + 0x84 (main.m:20)
13 ??? 0x00008e10 _start + 0x188 (crt.c:267)
14 ??? 0x00008c84 start + 0x30

Thanks

Yan

Same behaviour here. We should report this at the AppleScript Studio Users List…

Thanks. I didn’t know which list was best. Should I copy my message to that list then?

Yan

If you do, you’ll be talking to lots of ASStudio users, and… Apple’s engineers! :wink:

I can’t reproduce this behavior on my machine (Mac OS X 10.3.2 / US_EN / Xcode 1.1); the code works fine:
on open names
do shell script “ls”
display dialog “No Problem”
end open
Dropping a file on the app to start it brings up the dialog. And then I can quit it, nothing abnormal. This is using the unmodified AppleScript Droplet project that is installed with the Developer’s tools.

Jon

While neither John’s code nor hyanwong’s code cause a crash on my machine, I have had similar problems with some of my droplets.

The crashlogs for my droplets are virtually identical to Yan’s:


Host Name: mdouma46.local
Date/Time: 2004-01-28 17:19:01 -0500
OS Version: 10.3.2 (Build 7D24)
Report Version: 2

Command: Lproj Cleaner
Path: /Volumes/mdouma46/Documents/Programming/Lproj Cleaner/build/Lproj Cleaner.app/Contents/MacOS/Lproj Cleaner
Version: 1.0 (1.0)
PID: 1265
Thread: 0

Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
0 <<00000000>> 0x00000000 0 + 0
1 com.apple.AppleScriptKit 0x7f776f88 -[ASKApplicationOpenEventHandler handleAppleEvent:withReplyEvent:] + 0x7c
2 com.apple.Foundation 0x90a4a9d0 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 0x164
3 com.apple.Foundation 0x90a510b4 _NSAppleEventManagerGenericHandler + 0x78
4 com.apple.AE 0x92ccda68 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned long, unsigned char*) + 0xd0
5 com.apple.AE 0x92cd08b0 dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 0x2c
6 com.apple.AE 0x92ccdca8 aeProcessAppleEvent + 0x11c
7 com.apple.HIToolbox 0x928c47bc AEProcessAppleEvent + 0x3c
8 com.apple.AppKit 0x92dd2790 _DPSNextEvent + 0x358
9 com.apple.AppKit 0x92de8f34 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 0x74
10 com.apple.AppKit 0x92dfd27c -[NSApplication run] + 0x21c
11 com.apple.AppKit 0x92eb95f0 NSApplicationMain + 0x1d0
12 …epage.mdouma46.LprojCleaner 0x00008e1c _start + 0x188 (crt.c:267)
13 dyld 0x8fe1a700 _dyld_start + 0x64


In the case of my droplet, when it’s saved as an ordinary AppleScript droplet from Script Editor, it appears to work fine. But my AppleScript Studio droplet, which uses the same script, works fine if you drop only one file, but when you drop 2 or more, the script will succeed in executing it’s purpose, but will crash at the last moment. Here’s the code:

on open files_
    repeat with file_ in files_
        set file_info_ to the info for file_
        if alias of the file_info_ is false and the name extension of the file_info_ is "app" and package folder of file_info_ is true then
            set POSIX_file_ to POSIX path of file_
            set q_POSIX_file_C_R_ to (""" & POSIX_file_ & "Contents/Resources/")
            set sh_rm_combo_ to "rm -Rf " & q_POSIX_file_C_R_ & "A"*".lproj" " & ?
                q_POSIX_file_C_R_ & "B"*".lproj" " & ?
                q_POSIX_file_C_R_ & "C"*".lproj" " & ?
                q_POSIX_file_C_R_ & "D"*".lproj" " & ?
                q_POSIX_file_C_R_ & "F"*".lproj" " & ?
                q_POSIX_file_C_R_ & "G"*".lproj" " & ?
                q_POSIX_file_C_R_ & "I"*".lproj" " & ?
                q_POSIX_file_C_R_ & "J"*".lproj" " & ?
                q_POSIX_file_C_R_ & "K"*".lproj" " & ?
                q_POSIX_file_C_R_ & "N"*".lproj" " & ?
                q_POSIX_file_C_R_ & "P"*".lproj" " & ?
                q_POSIX_file_C_R_ & "S"*".lproj" " & ?
                q_POSIX_file_C_R_ & "d"*".lproj" " & ?
                q_POSIX_file_C_R_ & "en_"*".lproj" " & ?
                q_POSIX_file_C_R_ & "f"*".lproj" " & ?
                q_POSIX_file_C_R_ & "h"*".lproj" " & ?
                q_POSIX_file_C_R_ & "i"*".lproj" " & ?
                q_POSIX_file_C_R_ & "j"*".lproj" " & ?
                q_POSIX_file_C_R_ & "k"*".lproj" " & ?
                q_POSIX_file_C_R_ & "n"*".lproj" " & ?
                q_POSIX_file_C_R_ & "p"*".lproj" " & ?
                q_POSIX_file_C_R_ & "s"*".lproj" " & ?
                q_POSIX_file_C_R_ & "r"*".lproj" " & ?
                q_POSIX_file_C_R_ & "z"*".lproj""
            do shell script sh_rm_combo_
        end if
    end repeat
    quit
end open

Here’s the built version of the ASS app: http://homepage.mac.com/mdouma46/LprojCleaner.zip

BTW, this app is designed to delete all the language resources (except for English) from a package-type application. If you recently installed iCal 1.5.2 from Apple, and haven’t already deleted all its extra language resources, it might be a good candidate to use for this script. Make a couple copies onto your Desktop to use.

Any ideas what might be causing these crashes?

Yes, if you have the call to display dialog it doesn’t crash. In case you are interested, I got the following reply from an apple employee on the Applescript Users List

This workaround stops my crashes: I hope it may help MarkDouma.

Yan