☑️
Create a todo item

Script key: Create a todo item

Posted by justinashleylawii

Install

Details

Label ☑️
Voice Over Create a todo item
Script
var lineRange = getSelectedLineRange();
var line = getTextInRange(lineRange[0], lineRange[1]);
var selectedRange = getSelectedRange();


function addZeros(number)
{
	if(number <= 9){number = 0 + "" + number;}

	return number;
}

//If the first character in the line isn't a checkbox, or a cancelled checkbox, or a checked checkbox, then add a checkbox
if(!line || line.length == 0 || line[0] != "\u2610")
{
	if(line[0] == "\u2611" || line[0] == "\u2612")
	{
		line = "\u2610 " + line.substr(2, line.length - 2).trim();
		var index = line.lastIndexOf("*@");

		if(index){line = line.substring(0, index - 1) + "\n";}
	}
	else
	{
		line = "\u2610 " + line.trim() + "\n";
	}
}
else
{
	var timestamp = new Date();

	//Create timestamp
	var dateString = "";
	dateString += addZeros(timestamp.getHours()) + ":" + addZeros(timestamp.getMinutes()) + " " + (timestamp.getMonth() + 1) + "/" + timestamp.getDate() + "/" + timestamp.getFullYear();
	datestring = " *@" + dateString + "*";
	line = "\u2611 " + line.substr(2, line.length - 2).trim() + " " + datestring.trim() + "\n";

}

//Beginning of line
var lineStart = lineRange[0];
var lineLength = line.length - 1;

setTextInRange(lineRange[0], lineRange[1], line);

if(selectedRange[1] == 0)
{
	setSelectedRange(lineStart + lineLength, 0);
}
else
{
	setSelectedRange(lineStart, lineLength);
}

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus