23

I have a Java application that opens WebDAV files on MS Word. This works successfully on Windows with the next code:

Runtime.getRuntime().exec("cmd /c start winword " + webdavUrl);

But on Mac OSX this is not possible. I tried this function, but it only opens a blank document:

Runtime.getRuntime().exec(new String[]{"open", "-a", "Microsoft Word", webdavUrl});

if I create a file from the URL, I can open the file but I lose its reference to the WebDav URL.

I have found a discussion about a javascript code that can do this process from the browser.

Any thoughts?

Community
  • 1
  • 1
Tito Leiva
  • 892
  • 1
  • 12
  • 29
  • 1
    Maybe the solutions suggested here might be of help (e.g. the one using AppleScript): https://stackoverflow.com/questions/8387371/how-to-startup-a-mac-os-x-application-from-command-line . I'm not able to try these out at the moment though. – Dirk Vollmar Dec 08 '15 at 08:00
  • For anyone wondering why this doesn't work in Office 2016 for Mac, the reason is because WebDAV support was removed from this version of Office. – Luca Spiller Apr 04 '16 at 12:31

3 Answers3

5

First, can you access the directory where the word doc is? are you mounting your webdav?

I believe the terminal will be looking for a path, which is your webdavUrl. To debug, try running the same command but only with the -R and webdavUrl arguments.

Runtime.getRuntime().exec(new String[]{"open", "-R", webdavUrl});

-R will show the file in finder and this way you know that terminal can in fact navigate to your webdavUrl.

Ahmed Musallam
  • 9,523
  • 4
  • 27
  • 47
  • 1
    Also, take a look at the open command doc. It has all the arguments you can use. https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/open.1.html – Ahmed Musallam Dec 14 '15 at 04:16
  • 1
    you should edit `"-aR` to `"-aR"` in case someone copies you line of code to try it. – Adam Martinu Dec 14 '15 at 19:45
  • 1
    Thanks for the catch, it should be just -R – Ahmed Musallam Dec 14 '15 at 20:16
  • 1
    oh, hehe, my point was that you need an extra > " < though, otherwise your snippet will produce an error. So it should look like `"-R"`, sorry to bother you ^^ – Adam Martinu Dec 14 '15 at 20:22
  • 1
    I think you misunderstand the question. I want to open the file on Word in the same way you click on `File`and then `Open Url`. This process allows word to be connected directly to the server document throughout a WebDAV protocol and it is evident the change on the `Save Icon` where appears a `Sync`symbol. There is a [Javascript library](http://www.webdavsystem.com/ajax/programming/) that uses the Safari's SharePoint Browser Plug-In to open the document with WebDAV, so I'm searching the same solution but from the desktop and not throughout a browser like Safari. Thanks for the efforts anyway. – Tito Leiva Dec 16 '15 at 16:17
  • 1
    I see, Sorry I couldn't be of much help. Have you tried to mount the DAV server on OsX then opening the document from the mounted DAV (all using terminal)? and then maybe keep watching the document and when it's closed, you can un-mount the DAV server. Also, you might want to check [this article](https://community.office365.com/en-us/f/153/t/402550). It seems like open url feature with WebDav protocol will no longer be supporter starting with Microsoft office 2016. – Ahmed Musallam Dec 16 '15 at 17:51
2

You may try one of the following:

1: Use the Desktop Api as described here.

File myFile = new File(webdavUrl);
Desktop.getDesktop().open(myFile);

2: Use ms-word: uri as detailed here.

For example enter "ms-word:ofe|u|http://webdavUrl" on your browser. If you have Microsoft Office (2010 SP2+) installed this should open the word application with your document loaded.

The following resources might be helpful as they cover different ways you could open/edit word files in a webdav server.

Community
  • 1
  • 1
Yohannes
  • 115
  • 5
0

After almost 4 weeks of investigation, I succesfully developed a solution for this problem:

  1. First, on the server side, create an end-point to open the word document with the IT HIT's javascript library. This library uses the Sharepoint Browser Plugin to open the document on Word 2011 for Mac OSX with the Webdav protocol.
  2. Now on java, use the console to open Safari with the end-point URL to open the word document. For this, maybe you need to pass the document's URL as param for the end-point.

    Runtime.getRuntime().exec(new String[]{"open", "-a", "Safari", getWebdavUrl(document)});
    
    private static String getWebdavUrl(Document document) throws JSONException, UnsupportedEncodingException {
    
    RestClient client = RestClient.getClient();
    String baseUrl = client.SERVER_URL + "webdav_end_point";
    JSONObject params = new JSONObject();
    
    params.put("url", document.getUrl());
    
    //convert the JSON params to GET params for the URL
    String url = baseUrl + RestClient.buildParamsString(params);
    
    //https://wwww.example.com/webdav_end_point?url=www.example.com/path/to/webdav/document.docx
    return url;
    }
    

This allows to open the document on Word 2011 for MAC OSX, but you have to deal with the security and the user session if you have restrictions on the document edition. Anyway, I implemented this solution succesfully and it is the only solution I found that completes the process.

Tito Leiva
  • 892
  • 1
  • 12
  • 29
  • Re Mac use, be aware Chrome dropped the support for Java plugins, and for some reason I'm yet to understand, Mac Chrome will not automatically open a URL based on the ms-word: protocol introduced by office. Safari and the others DO so however. So on a MAC, you don't need to use IT HIT's library, you can just create a link to the document based on the ms-word: protocol. Now I wish I could figure out why Mac Chrome won't behave. – David Brown Mar 08 '16 at 10:51