Unexpected behavior with NSSavePanel's setAllowsOtherFileTypes

I have the following code to generate a save prompt.

    on getDDSavePath()
        set sp to current application's NSSavePanel's savePanel()
        sp's setTitle_("Choose a File")
        sp's setPrompt_("Save")
        sp's setMessage_("Select the dd backup save location.")
        sp's setNameFieldStringValue_("Untitled")
        sp's setCanCreateDirectories_(1)
        sp's setAllowedFileTypes_({"dd"})
        sp's setAllowsOtherFileTypes_(0)
        set returnCode to sp's runModal() as integer
        if returnCode = (current application's NSFileHandlingPanelOKButton) as integer then
            set ddTargetPath to (sp's directoryURL()'s |path|() as string) & "/" & (sp's nameFieldStringValue())
            log "Backup target is: " & ddTargetPath
            evaluateTargetPath()
        end if
    end getDDSavePath

When run, the default file name is “Untitled.dd” but a file name without an extension can be set. “Untitled” is accepted as a valid file name, as is “Untitled.foobar” where the expectation is that only “foobar.dd” would be acceptable. Trying to set the file name as “foobar.txt” does raise a “Required extension” dialog.

Additionally, I get unexpected behavior when trying to set an allowed file type with a dot in it. The code:

        sp's setNameFieldStringValue_("Untitled")
        sp's setAllowedFileTypes_({"dd.gz"})

produces a default file name of “Untitled.dd.gz.dd.gz” and allows any file name regardless of extension.

That’s not going to give you the correct result. You should use:

  set ddTargetPath to (sp's |URL|()'s |path|()) as text

As you will see, if you then enter a name without the correct extension, it will be appended automatically.

An allowed file type can have a dot only if it’s a UTI – an extension can’t have a dot by definition.