Zettelkasten Forum


Script: Get a random note from your archive

edited April 4 in Software & Gadgets

For a demonstration in my question about strengths of ties between notes, I've whipped up a Ruby script that will select a random plain text file from your archive directory.

Find the script here: https://gist.github.com/DivineDominion/0e72082a79359866a15558cba5c67e9a

Use it to fetch (up to) N unique notes from your note directory, at random. (It fetches less if you don't have enough notes at the path.)

Example

Command (default amount is 1)

$ ruby random_note.rb -d ~/Archive/

Example output:

201701161531 Automatic version numbering.md

Multiple Notes Example

Command

$ ruby random_note.rb -d ~/Archive/ -c 12

Example output:

201701161531 Automatic version numbering.md
201708211509 Buffer 3rd Wave Feminismus.txt
201309271825 Portable Kanban board.md
201607031406 User login session management in the Fabric app.md
201602201129 ambient interface.txt
201707272141 The 7 habits of highly effective artists.txt
201708231440 Why does ReSwift Middleware have dispatch.txt
2010-11-23_0757_R1_How to make introductions.md
201907060747 Send HTTP request from Ruby.txt
201611201032 Discipline necessitates purpose.md
201803221749 chmod settings for web server scripts.txt
201606050858 Function declaration kinds in JavaScript.txt

Sorted Example

Command, piping the output to sort:

$ ruby random_note.rb -d ~/Archive/ -c 12 | sort

Assuming same random example output of above:

2010-11-23_0757_R1_How to make introductions.md
201309271825 Portable Kanban board.md
201602201129 ambient interface.txt
201606050858 Function declaration kinds in JavaScript.txt
201607031406 User login session management in the Fabric app.md
201611201032 Discipline necessitates purpose.md
201701161531 Automatic version numbering.md
201707272141 The 7 habits of highly effective artists.txt
201708211509 Buffer 3rd Wave Feminismus.txt
201708231440 Why does ReSwift Middleware have dispatch.txt
201803221749 chmod settings for web server scripts.txt
201907060747 Send HTTP request from Ruby.txt
Post edited by ctietze on

Author at Zettelkasten.de • https://christiantietze.de/

Comments

  • Neat! I've tried something similar in that I my program gives me listings of unlinked, or too long zettels, picked randomly. It is fun to go and reprocess those when you have a moment of leisure.

    But, howabout connecting this with my last joke?

    It is very easy to get a good quality speech synthesis nowadays. Sign up for aws and download aws-cli and you get speech like this:

    aws --region eu-west-1 polly synthesize-speech \
                            --text-type ssml \
                            --text "<speak>Zettelkastens are fun</speak>" \
                            --output-format mp3 \
                            --voice-id Joanna --engine neural \
                            speech.mp3
    

    Now, what would happen if there was a program that, during your day read random zettels out loud? Or perhaps even followed links... :smile:

  • edited April 4

    @discordian said:
    It is very easy to get a good quality speech synthesis nowadays.

    and

    Sign up for aws and download aws-cli and you get speech like this

    are usually not thing I read next to each other :wink:

    I didn't know Amazon Web Services had a text-to-speech synthesizer, but it sounds quite alright. I pasted a couple of notes in the Polly web interface, but I couldn't stand listening to the result of my notes being read aloud daily. I now see that you picked the "Ivy" voice for your video, which is clearly the most fun to listen to, especially when she says "Epstein 2019, not citeable" :)

    Author at Zettelkasten.de • https://christiantietze.de/

  • Here a Keyboard Maestro macro that will produce a single random note in The Archive. I use it when I have time and inclination for sauntering in my Zettelkasten.

    Randomness Rules!

    Will Simpson
    I'm a Zettelnant.
    Research: Rationalism, Zen, Non-fiction Creative Writing
    kestrelcreek.com

  • On most Linux distributions you should also be able to do this with shuf

    The following will list 5 randomly chosen notes in the current directory:

    ls *.md | shuf -n 5
    
  • edited April 5

    Oh man! Of course there's a Unix command for that :D Dang

    Author at Zettelkasten.de • https://christiantietze.de/

  • I'm also pretty sure sort has a random option, and then there's head or tail...

  • D'uh, you're right: this works as well

    $ ls ~/Archive | sort -R | head -n 5
    

    Or use a find variant to filter the results first. I guess it's now even easier to see N random, unrelated notes.

    Author at Zettelkasten.de • https://christiantietze.de/

  • Funny enough, the man page for sort's random option references shuf, so it's all linked together.

Sign In or Register to comment.