In Google, the Google Apps Script project is stored on Google Drive as a single project file. If you download it via Google Drive syncing and open it locally, it will only contain the project ID. However, if you access this file on Google Drive itself, the file will contain all the project contents in json format.

It’s a small matter — to parse json, and save the contents of «virtual» files in the form of physical files of the appropriate format.

function main() {
    // This is the id of the script we want to export
    var scriptID = '***************************************************',
        // This is the id of the folder on Google Drive to which we will export
        targetFolderID = '******************************';
    var file = Drive.Files.get(scriptID);
    var url = file.exportLinks['application/'],
        options = {
            headers: {
                Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
    var response = UrlFetchApp.fetch(url, options);
    var files = JSON.parse(response).files;
    var folder = DriveApp.getFolderById(targetFolderID);
    for (var i = 0; i < files.length; i++) {
        var file = files[i],
            fileType = file.type,
            fileName =,
            fileSource = file.source;
        if (fileType == 'server_js') {
            fileType = 'gs';
        folder.createFile(fileName + '.' + fileType, fileSource);