Sandbox and Reveal in Finder

The code below tell the Finder to show a file in the Finder. When Sandboxed and this code runs “NOTHING” happens. no message.

      [code]          
        cmd = "osascript -e 'Tell application ""Finder"" to reveal """ + Native2AbsolutePath(file) + """' -e 'Tell application ""Finder"" to activate'"
        shell1.execute(cmd)[/code] 

Is there a way with Sandboxing to Reveal a file in the finder?

The

NSWorkSpaceMBS.selectFile(file as folderitem) as boolean

method will do it

see
http://www.monkeybreadsoftware.net/class-nsworkspacembs.shtml

(or look for a declare)

And the declare would be NSWorkSpace activateFileViewerSelectingURLs

Thank you, Google and Stack Overflow

I also have the activateFileViewerSelectingURLs method in the plugin.
But it’s for newer Mac OS X 10.6 and later and not sure what compatibility Jim needs.

Thanks Christian.

I’m also having problem with"

File.Launch

where file is folderitem.

Anything for that?

Another question. My MBS plugins subscription expires this month, will I get an email about renewing, soon?

Sandboxed apps may be limited in launching other apps.

For MBS, you can update today if you like and we simply extend your license.

Thanks Tim and Christian.

[quote=103007:@Jim Smith]I’m also having problem with"
File.Launch[/quote]

If the file has not been launched by the user first, the sandbox will not authorize it.

You can check this kind of errors with the Console utility, where messages will tell you what happened which prevented the launch.

Otherwise, I am using it within sandboxed apps and it works fine.

I don’t understand, if “launched by the user first”. Why would the app need to launch the file?

Have been using the Console, but sometime find it difficult to find where to look. Searches work sometime and some not.

[quote=103105:@Jim Smith]I don’t understand, if “launched by the user first”. Why would the app need to launch the file?

[/quote]

You mention file.launch. It is used either to open a document, or launch a program. As for why, it depends what your app does :wink:

My app is RVCare Log Book and the file(s) are references, like Pdf, text,jpg, etc. The user would click on the list to open the file. What I’m going to do is change to ‘reveal in Finder’ (which already works). Then the user would continue by clicking the finder file list.

However I don’t think there are very many user who use this feature. OH WELL!

I was having issues with a HTMLViewer CancelLoad earlier whereby I accidentally discovered ShowURL(FolderItem.URLPath) will open the file with it’s default application. Just for kicks, see if ShowURL works.

Instead of file.launch, for documents, I use a shell and the command Open. For instance Open toto.pdf would open the pdf file in the default reader, Preview, or Acrobat Reader. It works perfectly in a sandboxed application.

I had the following:

'cmd = "osascript -e 'Tell application ""Finder"" to reveal """ + Native2AbsolutePath(file) + """' -e 'Tell application ""Finder"" to activate'" 'shell1.execute(cmd)
and it was getting sandbox error, so I changed it to NSWorkSpaceMBS to get around the error.

Hi Jim,
There’s two issues with your original code.

  1. You’re using Apple Script, when Sandboxed you need to specify a entitlement that would allow your application to communicate with Finder.

  2. You’re trying to script the Finder, which Apple conser as security risk and therefore will reject your app from the App Store.

The API from NSWorkSpace is the correct method. I know it’s working for you, I just wanted to explain why.