Myriad Helpers, NSOpenPanel, and the Sandbox

Hi all,

I’ve been, for the most part, successfully re-writing an application of mine to use the glorious Myriad Helpers from Shane, but have run into an issue with NSOpenPanel that I just can’t figure out. The issue only occurs when Sandboxing is turned on. If Sandboxing is turned off, I get no errors and everything is just dandy.

Here’s the code:

set appContainerPath to (path to library folder from user domain)

tell current application's NSOpenPanel to set thePanel to makeOpenAt_types_files_multiples_prompt_title_(appContainerPath, {"txt", "pdf"}, true, false, "Choose a text or PDF file:", "My Open Title")
tell thePanel to showOver:mainWindow calling:{"openSheetDone:", me}

And here are the errors I get when the app is Sandboxed:

It looks to me as though the issue is with the path, appContainerPath. I’ve tried to inspect the variable (logging it, setting it as text and display dialoging it) with sandboxing turned on and off, but don’t see why this would be causing an error. Of course, path to library is different in the Sandbox, but it still appears to be a valid path.

Any insight? Thanks in advance!

The problem is with sandboxing. The open panel used by sandboxed apps is different from that used normally, and you are severely limited in what you can do with it. It won’t let you modify its behaviour by adding categories, which is what Myriad Helpers does.

I think half the issues I post about on here are caused by sandboxing. :stuck_out_tongue: Well, I’m not surprised…

I was able to get a customized NSOpenPanel to work using showOver with the following:

        
set userLibraryPath to (path to library folder from user domain)

set customOpenPanel to current application's NSOpenPanel's openPanel()
customOpenPanel's setCanCreateDirectories_(1)
customOpenPanel's setCanChooseFiles_(0) -- 1 allows choosing files, 0 disallows
customOpenPanel's setCanChooseDirectories_(1) -- 1 allows choosing folders, 0 disallows
customOpenPanel's setAllowsMultipleSelection_(0) -- 1 allows multiple selection, 0 disallows
customOpenPanel's setTitle_("This is a NSOpenPanel")
customOpenPanel's setPrompt_("This is a Button")
customOpenPanel's setMessage_("This is a message:")
customOpenPanel's setDirectoryURL_(current application's NSURL's URLWithString_("file://" & userLibraryPath))  ---- << This does not work

tell customOpenPanel to showOver_(mainWindow)

But of course things aren’t that simple. setDirectoryURL_ doesn’t work and also I am unable to retrieve the user selected file/folder URL from the NSOpenPanel. In addition, the panel is not dismissed properly. I tried adding the handler, but get a different unrecognized selector sent to instance error.


showOver_calling_(mainWindow, {"openSheetDone:", me})

Is it possible to implement a NSOpenPanel with a completion handler as sheet in a sandboxed app? I have a feeling that to get setDirectoryURL_ working I will have to go back to trying to understand Security Scoped bookmarks…

Neither am I…:frowning:

It is in Objective-C, I think. (I don’t use the sandbox, so I’m just guessing.)

Yep.

Is there a way to set the completionHandler for NSOpenPanel in AppleScriptObjC? Something like:

customOpenPanel's setCompletionHandler_("openPanelDone:")

or rather display the NSOpenPanel as a sheet using beginSheetModalForWindow_ instead of using showOver_ ?

A “completion handler” is a block, not a method, and you can’t do them in AppleScript.

There’s a deprecated method – beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo: – and it may still work, but you won’t get it into a store app.

I hope you’re logging all these issues as bug reports – that’s the only way there’s any chance they’ll ever get fixed.

Hello.

They should be able to let us use use script objects for blocks. Hopefully it will come in a later release.

Please log a feature request. It’s unlikely to happen, IMO, unless people ask for it.