OSACopyScriptingDefinitionFromURL() doesn't handle file: URLs correctly

Number:rdar://18944184 Date Originated:11-Nov-2014 08:23 PM
Status:Duplicate/14298245 Resolved:
Product:OS X Product Version:10.10, 10.9
Classification:Serious Bug Reproducible:Always
The OSACopyScriptingDefinitionFromURL() documentation (ASDebugging.h) states "If used with a file: URL, this call is equivalent to OSACopyScriptingDefinition."

However, using a file: URL returns an sdef containing Apple Event Manager's XML-RPC/SOAP terminology. This is a known bug (see Radar #15379481, #14298245) affecting OS X 10.10, 10.9, and probably earlier releases.

This bug needs to be fixed as the only alternative API, OSACopyScriptingDefinition(), requires an FSRef argument, which rules out its use in AppStore-hosted products and is generally undesirable due to the FSRef type and its associated functions being deprecated in 10.9.

The following code provides a quick and easy fix that can be applied with little or no tweaking:

extern OSAError OSACopyScriptingDefinitionFromURL(CFURLRef url, SInt32 modeFlags, CFDataRef *sdef) {
    OSAError err = noErr;
    CFStringRef scheme = CFURLCopyScheme(url);
    if (CFStringCompare(scheme, CFSTR("file"), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
        FSRef fs;
        if (!CFURLGetFSRef(url, &fs)) return fnfErr; // DEPRECATED API
        err = OSACopyScriptingDefinition(&fs, 0, sdef);
    } else {
        /* ORIGINAL OSACopyScriptingDefinitionFromURL IMPLEMENTATION GOES HERE */
    return err;


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!