Joined April 2014
·

Alex Berg

Denmark
·
·

The priority should have been 4-task.priority in stead of task.priority+1.

The code was more pretty printed when I pasted it. Also find files here: https://github.com/arberg/doitimExport

This will export all doit tasks in current view in Todoist ready import format with context, priorities, notes, and tags (where tags are made into labels, and contexts made into labels starting with a c).

I run this script once per project, because todoist only support import a project at a time, unless its API is used (I think). So I click a project in doit.im, then I run the script in Chrome Console, paste to file, and create a new todoist project, choose import, and drag file into todoist import - at least I do this for my larger projects. For smaller projects, I just batch it into one todoist project, and separate from there.

function contextLookup(ctxId) {
var arr = Doit.contexts;
for(var i=0; i< arr.length; i++) {
if (arr[i].uuid == ctxId) return arr[i].name;
}
return "missing";
}

function projLookup(projId) {
var projects = Doit.projects;
for(var i=0; i< projects.length; i++) {
if (projects[i].uuid == projId) return projects[i].name;
}
return "missing";
}

var noteNewline = '\x09';
var noteEnd = "\n";//0x09;
var projSeparator = "#";
var tagSeparator = "@";
var ctxSeparator = "@c";
var allTaskLines = "";
var noTasks = TASKS.length;
for (var i = 0; i < noTasks; i++) {
var task = TASKS[i];
var thisTaskLine = task.title;
//var thisTaskLine = thisTaskLine +" ^"+task.attribute;
// var thisTaskLine = thisTaskLine +" "+projSeparator+projLookup(task.project);
var thisTaskLine = thisTaskLine +" "+ctxSeparator+contextLookup(task.context).toLowerCase().replace(/[ ]/g, "");
var tags = task.tags;
if (!(typeof tags === 'undefined')) {
var noTags = task.tags.length;
for (var j = 0; j < noTags; j++) {
var lowerSpaceTagWithoutSpaces = tags[j].toLowerCase().replace(/[ ]/g, "");
thisTaskLine = thisTaskLine + " " + tagSeparator + lowerSpaceTagWithoutSpaces;
}
}
var thisTaskLine = thisTaskLine +" [[priority "+(task.priority+1)+"]]";
if (!(typeof task.notes === 'undefined')) {
// replace new lines in notes with '/n', because I want one task on each line
var notes = task.notes.replace(/[\r\n]/g, noteNewline).replace(/[\n]/g, noteNewline);
var thisTaskLine = thisTaskLine +noteEnd+"[[NOTE]]: "+notes;
}
allTaskLines = allTaskLines + thisTaskLine + "\n";
}
console.log(allTaskLines);
copy(allTaskLines);

The paste went wrong in the post, hence the command didn't work. rdrunner (above comment) has given the correct command with plus'es and backslash before n for newline.

Note that this export does not export the tags, but just the project name. The printer by leeiio,http://lab.leeiio.me/printdo/,
also exports the project names and is probably easier to get to work for most people than this chrome console. It's possible to create export containg tags with a simple Chrome Console script, I can see the tags in an array when I refresh the doit.im page in the console, but I don't know how to access them programatically.

Below I have included various versions of coderwalls script, each doing something differently (exporting title, or project name, or context). I don't know how to concatenate to one line in a javascript.

var taskString = ''; var tasks = $('.taskList .task .title .link-title').text(function(index, value) {
taskString = taskString +'- ' + value + "\n";
}); console.log(taskString); copy(taskString);

var taskString = ''; var tasks = $('.taskList .task .title .context').text(function(index, value) {
taskString = taskString + value + "\n";
}); console.log(taskString); copy(taskString);

var taskString = ''; var tasks = $('.taskList .task .title .project').text(function(index, value) {
taskString = taskString + value + "\n";
}); console.log(taskString); copy(taskString);

var taskString = ''; var tasks = $('.taskList .task .title');
tasks.text(function(index, value) {
taskString = taskString + value + "\n";
}); console.log(taskString); copy(taskString);

Achievements
7 Karma
0 Total ProTip Views
Interests & Skills