I've found no direct way of opening a created document through Google Apps Script (GAS), via GAS. There's however an indirect way, which is presented below. It uses an Anchor element to show a pre-formatted hyperlink.
Code
// global
var ss = SpreadsheetApp.getActive();
function onOpen() {
var menu = [{name: "Create Document", functionName: "createDoc"}];
ss.addMenu("Extra", menu);
}
function createDoc() {
var sh = ss.getActiveSheet(), aRow = sh.getActiveCell().getRowIndex();
var title = sh.getRange(aRow, 1).getValue(), docDate = new Date();
var docTitle = title + "-" + docDate, doc = DocumentApp.create(docTitle);
var url = doc.getUrl();
// create app and panel
var app = UiApp.createApplication().setTitle("Open Google Document")
.setHeight(50).setWidth(400);
var vPanel = app.createVerticalPanel()
.add(app.createAnchor(docTitle, url));
// add to app
app.add(vPanel);
ss.show(app);
}
Screenshot
Remarks
This piece of code creates a new menu entry called "Extra" upon opening of the file. The selection "Create Document" will create (in the back gound) a Google Document and displays a panel with a hyperlink to open the document.
Example
I've created an example file for you: How To Open Document
I'm afraid that this isn't possible. (At least, not right now.)
A quick perusal of the Google Drive support forums shows other people also wanting to have more dynamic mailto:
links in their Google Documents. (Surprisingly, this might be easier to do with Google Spreadsheets and the =hyperlink()
function.)
Anyway, I did some experimentation.
A mailto:
link with one Email address will work.
mailto:bigal@example.com
However, it has to be an email address. Using a name (so that Outlook will search for it in your address book) doesn't work.
I also tried a couple of other tricks to get multiple addresses in the link.
mailto:bigal@example.com?cc=littlejohn@example.com
That doesn't work. Nor did separating email addresses with commas instead of semi-colons, so that's not an issue.
So, it appears that in a Google Document you're limited to the very simplest mailto:
link.
Assuming you're "locked in" to the Google eco-system, your options at this point are to either put email addresses into the document as plain text (so people can copy-paste directly to their email client compose window) or create an email alias for each group of people who should receive email messages from a document. (That last is certainly impractical for even small shops.)
Best Answer
This problem happens to me sometimes on my Ubuntu (its a laptop). This usually happens as Google Docs is trying to establish a connection between your computer and Google's servers, so that whatever you type can be saved automatically.
It is "locked" as a safety measure in case a connection cannot be established fast enough and you are about to close the document that you have already been working on (i.e. added content).