Took a second to update my morning writing workflow. Before, I was using a plug-in in Obsidian to see a word cloud of all my free-writing gibberish. I'd love to automate that step, so I found some JavaScript that I could drop into an Apple Shortcut. I'll add the script below.
So now my morning flow is to run the Morning shortcut. The shortcut:
- Creates a random linear drum pattern and puts it in my task list for Today
- Asks me what I did yesterday and appends it to a text file called Story
- Asks me what I learned yesterday and appends it to a text file called Wisdom
- Selects one random Japanese grammar for me to practice and puts it in my task list for Today
- Selects one thing to deep clean from a list and puts it in my task list for Today
Doing this seems to incrementally move the pieces forward.
Here is the Javascript for counting all the words in all the text files in a folder.
function run(input) {
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var folderPath = input; // Get selected folder
var wordCount = {};
// Get list of .txt files
var files = app.doShellScript(`find "${folderPath}" -type f -name "*.txt"`).split("\r");
files.forEach(function(file) {
var content = app.doShellScript(`cat "${file}"`).toLowerCase();
var words = content.match(/\b+\b/g); // Extract words
if (words) {
words.forEach(function(word) {
if (word.length > 3) { // Ignore short words
wordCount = (wordCount || 0) + 1;
}
});
}
});
// Sort words by frequency
var sortedWords = Object.entries(wordCount).sort((a, b) => b - a).slice(0, 100);
// Create output text
var output = "# Top 100 Words Used:\n\n" + sortedWords.map(([word, count]) => `${count}: ${word}`).join("\n");
return output; // Send to Drafts
}