sandboxing and filename extensions

  • On 10.6.8, if I enter a plain filename without extension, the save panel returns the path with the extension appended. On 10.7.5, where sandboxing kicks in and this actually matters because the code cannot normalize the returned name, the save panel returns the path WITHOUT extension. The code is simple enough:

    NSSavePanel * pnl = [NSSavePanel savePanel];
    [pnl setTitle: ...];
    [pnl setPrompt: ...];
    [pnl setNameFieldLabel: ...];
    [pnl setAllowedFileTypes: [NSArray arrayWithObject: @"pdf" ]];
    [pnl setAllowsOtherFileTypes: NO];
    [pnl beginSheetForDirectory: ...];

    Is there something I need to configure in my app's info plist to specify that the app is expected to create .pdf files???

    --
    Scott Ribe
    <scott_ribe...>
    http://www.elevated-dev.com/
    (303) 722-0567 voice
  • On May 14, 2013, at 21:16 , Scott Ribe <scott_ribe...> wrote:

    > On 10.6.8, if I enter a plain filename without extension, the save panel returns the path with the extension appended. On 10.7.5, where sandboxing kicks in and this actually matters because the code cannot normalize the returned name, the save panel returns the path WITHOUT extension.

    Could you clarify a couple of things…

    Are you typing the file name into the Save panel, or just pressing Enter to use the pre-filled name? What are the settings for "canSelectHiddenExtension" and "isExtensionHidden"? What is the behavior on 10.8.3?

    I seem to recall noticing a change in behavior in some system version, where the save panel no longer added the extension when it was missing. This was either on the initial file name pre-filled in the panel, or on entering an extension-less name when the checkbox indicating "isExtensionHidden" was unchecked, or something like that. But my recollection on this is very hazy, sorry.

    Does it make any difference if you use the UTI for PDF files instead of the literal string "PDF" for the extension? We already know that the powerbox Save panel doesn't implement everything the regular one does, and it may have some limitations for non-UTI type strings.
  • On May 15, 2013, at 1:03 AM, Quincey Morris wrote:

    > Could you clarify a couple of things…
    >
    > Are you typing the file name into the Save panel, or just pressing Enter to use the pre-filled name? What are the settings for "canSelectHiddenExtension" and "isExtensionHidden"? What is the behavior on 10.8.3?

    Typing the file name in. In fact, although I hadn't tried it until you made me think of it, pre-filling the name (with setNameFieldStringValue:) does not work in a sandboxed app. I do not set the options about hidden extensions--I do not want this dialog to be different than the system default. The behavior on 10.8.3 is the same in all cases.

    Also, I earlier tried fiddling with the options about hidden extensions, and that made no difference. And I changed my Finder preferences back to default, turning off "show all file extensions", and that made no difference.

    > I seem to recall noticing a change in behavior in some system version, where the save panel no longer added the extension when it was missing. This was either on the initial file name pre-filled in the panel, or on entering an extension-less name when the checkbox indicating "isExtensionHidden" was unchecked, or something like that. But my recollection on this is very hazy, sorry.
    >
    > Does it make any difference if you use the UTI for PDF files instead of the literal string "PDF" for the extension? We already know that the powerbox Save panel doesn't implement everything the regular one does, and it may have some limitations for non-UTI type strings.

    Using @"com.adobe.pdf" makes no difference.

    I guess about the only thing I can do here in order to get the file named in a usable manner (since Apple so wisely ditched _all_ support for "old-fashioned" file types), is to use a delegate, implement panel:validateURL:error:, and force the user to type ".pdf". Ugh.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.elevated-dev.com/
    (303) 722-0567 voice
  • On May 15, 2013, at 08:31 , Scott Ribe <scott_ribe...> wrote:

    > I guess about the only thing I can do here in order to get the file named in a usable manner […] is to use a delegate, implement panel:validateURL:error:, and force the user to type ".pdf".

    I don't believe this. If true, it would suggest that sandboxed Save panels are so broken that no one could save anything without typing the correct extension.

    In fact, I'm not seeing the behavior you describe. In an existing sandboxed app of mine, there's an Export function that does the right thing. The code is like this:

    > NSSavePanel* savePanel = [NSSavePanel savePanel];
    >
    > savePanel.title = …
    > savePanel.prompt = …
    > savePanel.nameFieldLabel = …
    > savePanel.canCreateDirectories = YES;
    > savePanel.canSelectHiddenExtension = YES;
    > savePanel.allowedFileTypes = [NSArray arrayWithObject: @"abc"];
    >
    > NSString* exportDirectory = …
    > if (exportDirectory)
    > savePanel.directoryURL = [NSURL fileURLWithPath: exportDirectory];
    >
    > NSString* exportFileName = [[self.document displayName] stringByDeletingPathExtension];
    > exportFileName = [exportFileName stringByAppendingString: @" Export"];
    > exportFileName = [exportFileName stringByAppendingPathExtension: @"abc"]; // <-- this
    > savePanel.nameFieldStringValue = exportFileName;
    >
    > [savePanel beginSheetModalForWindow: [self.document windowForSheet] completionHandler: ^(NSInteger result)
    > {
    > … savePanel.URL …
    > }];

    (The line labeled "<-- this" is, IIRC, the change I referred to earlier. Originally, there was no need to supply the extension explicitly there, but somewhere around 10.7, it became necessary.)

    Because of "canSelectHiddenExtension", my Save dialog has a "Hide Extension" checkbox. If it's unchecked, and I retype the file name text box without an extension, the checkbox turns itself on automatically. If I type the correct extension, the checkbox turns itself off automatically. (If I type an incorrect extension, the checkbox turns on. I assume I'd get something like "filename.def.abc" in that case.)

    No matter whether the extension is shown in the text field, the Save panel returns a URL with the correct extension. I have no idea why you might be seeing different behavior. Except …

    On May 14, 2013, at 21:16 , Scott Ribe <scott_ribe...> wrote:

    > [pnl beginSheetForDirectory: ...];

    When comparing your code with mine, I realized that -[NSSavePanel beginSheetForDirectory: …] was deprecated in 10.6. Try using one of the non-deprecated methods. It *does* matter, with powerbox.
  • On May 15, 2013, at 11:39 AM, Quincey Morris wrote:

    > Because of "canSelectHiddenExtension", my Save dialog has a "Hide Extension" checkbox. If it's unchecked, and I retype the file name text box without an extension, the checkbox turns itself on automatically. If I type the correct extension, the checkbox turns itself off automatically. (If I type an incorrect extension, the checkbox turns on. I assume I'd get something like "filename.def.abc" in that case.)

    That is *exactly* the behavior that I see in 10.6, but not at all what happens in 10.7 or 10.8.

    > No matter whether the extension is shown in the text field, the Save panel returns a URL with the correct extension.

    Yes, in 10.6.

    > I have no idea why you might be seeing different behavior. Except …

    > On May 14, 2013, at 21:16 , Scott Ribe <scott_ribe...> wrote:
    >
    >> [pnl beginSheetForDirectory: ...];
    >
    > When comparing your code with mine, I realized that -[NSSavePanel beginSheetForDirectory: …] was deprecated in 10.6. Try using one of the non-deprecated methods. It *does* matter, with powerbox.

    Well, I missed that--stared at other documentation until my eyes bled, and got rid of setRequiredFileType: because it was deprecated. I will give that a try. Haha, I see that beginSheetForDirectory has such a long method name that the "Deprecated in Mac OS X v10.6" message is not visible without horizontal scrolling in my window. Excuse me while I go grind my teeth for a while.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.elevated-dev.com/
    (303) 722-0567 voice
  • On May 15, 2013, at 11:39 AM, Quincey Morris wrote:

    > When comparing your code with mine, I realized that -[NSSavePanel beginSheetForDirectory: …] was deprecated in 10.6. Try using one of the non-deprecated methods. It *does* matter, with powerbox.

    Well, that was the problem. FYI, I'm still supporting 10.5, so had never bumped the Base SDK beyond that, so wasn't getting compiler warnings about that deprecated method.

    Anyway, THANKS--I'm not sure I would ever have noticed that.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.elevated-dev.com/
    (303) 722-0567 voice
  • On May 15, 2013, at 10:31 AM, Scott Ribe <scott_ribe...> wrote:

    > Using @"com.adobe.pdf" makes no difference.

    This doesn't relate to your problem, but technically, the best thing to use is probably the constant (__bridge NSString *)kUTTypePDF, rather than hard-coding either the extension or the UTI directly into the app.

    Charles
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today