Issue with NSSavePanel. Error when getting the URLs()

I need a NSURL for a file path because I later want to use it with NSSpeechSynthesizer’s startSpeakingString:toURL.

This is my bit of ASObj-C code for letting the user select the path and file name.


set outputFile to current application's NSSavePanel's savePanel()
tell outputFile
            setAllowedFileTypes_({"aif"})
            setAllowsOtherFileTypes_(0)
            setCanCreateDirectories_(1)
            setTitle_("Output File")
            setNameFieldStringValue_("File Name")
            setShowsHiddenFiles_(0)
            setTreatsFilePackagesAsDirectories_(0)
            runModal()
end tell
        set outputFileURL to outputFile's URLs()
    

The problem is that I get the error “Can’t make «class ocid» id «data optr0000000020E5010000600000» into type Unicode text. (error -1700)” on the line

set outputFileURL to outputFile's URLs()

I’m working in XCode 5/Mavericks. Hopefully someone can point me in the right direction of what I’m doing wrong.

Thanks
Tim

Model: iMac
AppleScript: 2.3.1
Browser: Safari 537.36
Operating System: Other

I suspect that error is happening somewhere else, when you try to coerce the value. Can you post the following code?

Here’s the whole handler.


    on exportAIFF_(sender)
        
        set voiceText to textField's stringValue()
        
        set outputFile to current application's NSSavePanel's savePanel()
        tell outputFile
            setAllowedFileTypes_({"aif"})
            setAllowsOtherFileTypes_(0)
            setCanCreateDirectories_(1)
            setTitle_("Output File")
            setNameFieldStringValue_("File Name")
            setShowsHiddenFiles_(0)
            setTreatsFilePackagesAsDirectories_(0)
            runModal()
        end tell
        set outputFileURL to outputFile's URLs()
    

        set outputSynth to current application's NSSpeechSynthesizer's new()
        outputSynth's setDelegate:me
        outputSynth's startSpeakingString:voiceText toURL:outputFileURL

        display dialog "Export is Finished"


    end exportAIFF_

URLs() returns an array of URLs. Use URL() instead.

Tried that and I still get an error “Can’t get «class url » {} of «class ocid» id «data optr00000000E02C310001000000». (error -1728)” At least it is a slightly different error.

I suspect you have a terminology clash, with a scripting addition using “URL”. Try |URL|().

The best way to avoid this sort of thing, especially with Mavericks, is to edit your text in an external editor – the syntax colouring should make this sort of problem obvious. Click on the file in the Project Navigator, and choose File → Open with External Editor.

Thank you so much Shane. That did it.

I really need to upgrade to the latest version of your book!

Thanks again.
Tim