Skip to content

Instantly share code, notes, and snippets.

@brokosz
Created December 19, 2025 15:21
Show Gist options
  • Select an option

  • Save brokosz/82487557f355d7666c5f773f43c78008 to your computer and use it in GitHub Desktop.

Select an option

Save brokosz/82487557f355d7666c5f773f43c78008 to your computer and use it in GitHub Desktop.
JXA script to convert Markdown back to TaskPaper format. Preserves date tags, project tags, and task completion status.
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
const app = Application.currentApplication();
app.includeStandardAdditions = true;
let content;
if (argv.length > 0) {
// Use file from command line
content = app.read(Path(argv[0]));
} else {
// Use clipboard
content = app.theClipboard();
}
const lines = content.split(/\r\n|\r|\n/);
let taskpaper = '';
for (let line of lines) {
if (line.trim() === '') {
taskpaper += '\n';
} else if (line.startsWith('## ')) {
taskpaper += `${line.slice(3)}:\n`;
} else if (line.includes('- [x]')) {
let task = line.replace(/.*-\s*\[x\]\s*/, '').trim();
const doneDateMatch = task.match(/#done-(\d{4}-\d{2}-\d{2})/);
const doneDate = doneDateMatch ? doneDateMatch[1] : new Date().toISOString().split('T')[0];
if (doneDateMatch) {
task = task.replace(/#done-\d{4}-\d{2}-\d{2}/, '').trim();
}
task = task.replace(/#due-(\d{4}-\d{2}-\d{2})/g, '@due($1)')
.replace(/#start-(\d{4}-\d{2}-\d{2})/g, '@start($1)')
.replace(/#([A-Z][a-zA-Z]*)/g, '@project($1)')
.replace(/#(\w+)/g, '@$1').trim();
taskpaper += `\t- ${task} @done(${doneDate})\n`;
} else if (line.includes('- [ ]')) {
let task = line.replace(/.*-\s*\[\s*\]\s*/, '').trim();
task = task.replace(/#due-(\d{4}-\d{2}-\d{2})/g, '@due($1)')
.replace(/#start-(\d{4}-\d{2}-\d{2})/g, '@start($1)')
.replace(/#([A-Z][a-zA-Z]*)/g, '@project($1)')
.replace(/#(\w+)/g, '@$1').trim();
taskpaper += `\t- ${task}\n`;
} else {
taskpaper += `${line}\n`;
}
}
app.setTheClipboardTo(taskpaper);
console.log("Converted Markdown to TaskPaper and copied to clipboard");
return taskpaper;
}
@brokosz
Copy link
Author

brokosz commented Dec 19, 2025

Usage

Markdown → TaskPaper:

osascript markdown-to-taskpaper.js                    # From clipboard
osascript markdown-to-taskpaper.js file.md            # From file

Conversions

TaskPaper Markdown
Project: ## Project
- task - [ ] task
- task @done - [x] task
@due(2025-12-18) #due-2025-12-18
@start(2025-12-18) #start-2025-12-18
@project(Name) #Name (capitalized)
@tag #tag

Output goes to clipboard for easy pasting between apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment