My goal is to turn automatically the (very) long share links generate by Google drive for his documents in the short url: goo.gl/code
I found the beautiful script from Jacob Jan Tunistra here, but that post is now closed.
Jacob's code works like a charm but you need to run it. My needs are to run the script automatically when you open the document (and not to open the menu e push the button. How can I modify that script please?
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("Shorten")
.addItem("Go !!","rangeShort")
.addToUi()
}
function rangeShort() {
var range = SpreadsheetApp.getActiveRange(), data = range.getValues();
var output = [];
for(var i = 0, iLen = data.length; i < iLen; i++) {
var url = UrlShortener.Url.insert({longUrl: data[i][0]});
output.push([url.id]);
}
range.offset(0,1).setValues(output);
}