{"id":104,"date":"2014-11-05T14:02:52","date_gmt":"2014-11-05T03:02:52","guid":{"rendered":"http:\/\/stuff.magicwilly.home\/?p=104"},"modified":"2014-11-05T14:02:52","modified_gmt":"2014-11-05T03:02:52","slug":"google-apps-script","status":"publish","type":"post","link":"http:\/\/stuff2.mygeekvps.net\/index.php\/2014\/11\/05\/google-apps-script\/","title":{"rendered":"Google Apps Script"},"content":{"rendered":"<p>Just having a play with some Google apps scripting.<br \/>\n<!--more--><\/p>\n<pre lang=\"javascript\" cssfile=\"none\">\n\/\/ Nothing is deleted just archived.\n\/\/\n\/\/ Look in All Mail if you don't see it in the InBox.\n\/\/\n\/\/ Script runs each night between 11pm and midnight.\n\/\/\n\/\/ Archives mail in the inbox that is more than two days old both read and unread.\n\/\/\n\/\/ If you want something not to be archived give it a yellow star.\n\/\/\nfunction archiveInbox() {\nvar threads = GmailApp.search('label:inbox older_than:2d -has:yellow-star');\nfor (var i = 0; i &lt; threads.length; i++) {\nthreads[i].moveToArchive();\nUtilities.sleep(5000);\n}\n}\nfunction archiveTrigger() {\nScriptApp.newTrigger(\"archiveInbox\")\n.timeBased()\n.atHour(23)\n.everyDays(1) \/\/ Frequency is required if you are using atHour() or nearMinute()\n.create();\n}\n<\/pre>\n<p>All this good info came from <a href=\"http:\/\/www.johneday.com\/422\/time-based-gmail-filters-with-google-apps-script\" target=\"_blank\" rel=\"noopener noreferrer\">here&#8230;<\/a><br \/>\n&nbsp;<br \/>\nBelow is the improved version&#8230;.<\/p>\n<pre lang=\"javascript\" cssfile=\"none\">\n\/\/ Created this script as the shared garden inbox was filling up with rubbish.\n\/\/\n\/\/ Nothing is deleted just archived.\n\/\/\n\/\/ Look in All Mail if you don't see it in the InBox.\n\/\/\n\/\/ Script runs each night between 11pm and midnight.\n\/\/\n\/\/ Archives mail in the inbox that is more than two days old both read and unread.\n\/\/\n\/\/ If you want something not to be archived give it a yellow star.\n\/\/\nfunction archiveInbox() {\nvar inThreads = GmailApp.search(\"'in:inbox older_than:2d'\");\nfor (var i = 0; i < inThreads.length; i++) {\ninThreads[i].moveToArchive()\nUtilities.sleep(3000);\n}\nvar sentThreads = GmailApp.search(\"'in:sent newer_than:2d'\");\nfor (var j = 0; j < sentThreads.length; j++) {\nsentThreads[j].moveToInbox();\n}\nvar starThreads = GmailApp.search('is:starred');\nfor (var k = 0; k < starThreads.length; k++) {\nstarThreads[k].moveToInbox();\n}\n}\nfunction archiveTrigger() {\nScriptApp.newTrigger(\"archiveInbox\")\n.timeBased()\n.atHour(23)\n.everyDays(1) \/\/ Frequency is required if you are using atHour() or nearMinute()\n.create();\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Just having a play with some Google apps scripting.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-server"],"_links":{"self":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":0,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"wp:attachment":[{"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/stuff2.mygeekvps.net\/index.php\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}