function search() {
// Prompt the user for a search term
var searchTerm = Browser.inputBox("Enter the string to search for:");
// Get the active spreadsheet and the active sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
// Set up the spreadsheet to display the results
var headers = [["File Name", "File Type", "URL"]];
sheet.clear();
sheet.getRange("A1:C1").setValues(headers);
// Search the files in the user's Docs List for the search term
var files = DocsList.find(searchTerm);
// Loop through the results and display the file name, file type, and URL
for (var i = 0; i < files.length; i++) {
sheet.getRange(i+2, 1, 1, 1).setValue(files[i].getName());
sheet.getRange(i+2, 2, 1, 1).setValue(files[i].getType());
if (files[i].getType() == "document") {
urlBase = "https://docs.google.com/Doc?docid=";
}
else if (files[i].getType() == "spreadsheet") {
urlBase = "https://spreadsheets.google.com/ccc?key=";
}
else if (files[i].getType() == "presentation") {
urlBase = "https://docs.google.com/present/view?id=";
}
else {
urlBase = "https://docs.google.com/fileview?id=";
}
sheet.getRange(i+2, 3, 1, 1).setValue(urlBase + files[i].getId());
}
}
|
|