NSSavePanel Problem

I have been working with the showModalSave_ save panel from Shane’s book and am running into a problem. I have copied it directly out of the book (3rd edition) and I get an “unrecognized selector sent…” error. It seems that the problem is the setDirectoryURL_ portion of the code. When I comment this part out it works fine.

But I want the save panel to automatically take you to a certain folder on the desktop to save to. How can I accomplish this? Any help would be greatly appreciated.

Thanks…

Hi,

I guess you passed a string path as parameter for setDirectoryURL_ but it expects an URL.
You can create an URL with


current application's NSURL's fileURLWithPath_(path)

It might be that you have to wrap NSURL in pipes

is still cannot seem to get this to work. I still get the same error . Here is the code, I am sure that I incorporated your suggestion the wrong way…


    on showModalOpen_()
        set myFile to {}
        set thePanel to current application's NSOpenPanel's openPanel()
        set myDirectoryPath to current application's |NSURL|'s fileURLPath_("/Desktop/Product PSD/")
        tell thePanel
            setMessage_("Open File:")
--            setAllowedFileTypes_({"tif"})
            setTitle_("My Open Panel")
            setShowsHiddenFiles_(false)
            setDirectoryURL_(myDirectoryPath)
            setCanChooseFiles_(true)
            setCanChooseDirectories_(true)
            setAllowsMultipleSelection_(true)
            set returnCode to runModal()
        end tell
        set returnCode to returnCode as integer
        if returnCode = (current application's NSFileHandlingPanelOKButton) as integer then
            set theURLs to thePanel's URLs() as list
            set progressCount to count of theURLs
            repeat with i from 1 to count of theURLs
                tell item i of theURLs to set thePosixPath to |path|()
                log thePosixPath
                set hfsPath to (((thePosixPath as text) as POSIX file) as text)
                log hfsPath
                set end of myFile to hfsPath
                log myFile
            end repeat
            else
            log "Cancel pressed"
            error -128
        end if
    end showModalOpen_

fileURLWithPath

and you must specify the full path


set thePanel to current application's NSOpenPanel's openPanel()
set productFolder to POSIX path of (path to desktop) & "Product PSD/"
set myDirectoryPath to current application's |NSURL|'s fileURLWithPath_(productFolder)
        tell thePanel
.

Thanks for your help StefanK, i seen that I left the With out a bit after I posted. You have been a great help!

FYI, this is covered at:

www.macosxautomation.com/applescript/apps/errata.html

Strangely enough, it did actually work with a path in OS X 10.6.