A command line tool to quickly save tweets as Markdown.
Report a Bug
·
Request a Feature
Twitter will remove free access to the Twitter API on Feb. 13th, 2023. At that time, the only way you'll be able to use this tool is if you sign up and pay for a Twitter bearer token (basic access is listed at $100 per month).
I will no longer be continuing development on this tool.
This command line tool allows you to quickly save a tweet in Markdown format. This is great for Zettelkasten note-taking or any other commonplace notebook, vade mecum, Obsidian, Roam, Foam, &c. It is built on the new Twitter v2 API.
⚠ You'll need to have Node.js of at least v12.x
to use this tool.
You can install this CLI tool by running
yarn global add tweet-to-markdown
or
npm install --global tweet-to-markdown
You can also run it without installing:
npx tweet-to-markdown
To use this tool, you must sign up for a bearer token through the Twitter Developer dashboard. Twitter is ending free access to their API on Feb. 13th, 2023. Basic access is listed at $100 per month.
To get a bearer token from Twitter, you'll need to set up an application on the Twitter developer dashboard. For a guide on doing so, see Getting a bearer token. Once you have the bearer token, either store it in the environment variable TWITTER_BEARER_TOKEN
or pass it to the command line tool with the -b
(--bearer
) flag with each call.
Grabbing a tweet is as easy as calling the ttm
command and passing in the tweet URL.
ttm -b "<bearer token>" https://twitter.com/JoshWComeau/status/1213870628895428611
# Tweet saved as JoshWComeau - 1213870628895428611.md
Nota bene: If passing your bearer token as an argument instead of an environment variable, wrap your bearer token or API key in quotes to prevent any special symbols from being misinterpreted by the command line. Also, if using a TTM API key, be sure to include the entire key, from the TTM
at the beginning all the way to the end with the alphanumeric characters (e.g. "TTM>asdf1123"
or "TTM_ghjk4567"
).
The tweet will be saved to a Markdown file in the current directory. Here's how the tweet will look:
Any attached images, polls, and links will also be linked and displayed in the file.
There are many options to customize how this tool works. It is highly recommended to find the options you need and set up an alias in your terminal.
For example on Mac or Linux, you can define an alias with your options like so:
alias ttm="ttm -p $HOME/notes --assets --quoted"
For Windows, have a look at DOSKEY.
What if you want to just copy the Markdown to the clipboard instead of saving to a file? Just pass the -c
(--clipboard
) flag.
ttm -c https://twitter.com/JoshWComeau/status/1213870628895428611
#Tweet copied to the clipboard.
If you would like to include quoted tweets, pass the -q
(--quoted
) flag. This is disabled by default because a separate request has to be made to fetch the quoted tweet.
ttm <tweet url> -q
To capture an entire tweet thread, use the -t
(--thread
) flag and pass the URL of the last tweet in the thread.
Nota bene: this will make a separate network request for each tweet.
ttm <last tweet url> -t
Instead of showing complete, individual tweets with profile picture, date, etc. when downloading a thread, this option will show the header once and then only show the tweet bodies, representing tweet threads as a cohesive body of text. A header will be shown if a different author appears in the thread, for example if you're downloading a conversation between various authors.
ttm <last tweet url> -T
These follow the same rules as condensed threads, but each tweet will still be separated by ---
.
ttm <last tweet url> -s
With this flag, only the text of the tweet itself will be included. No author tags, frontmatter, or other information will be attached.
Nota bene: This has not been tested well with threads. Please use at your own risk. Condensed threads may be a better fit for you.
In order to save the tweet with a custom filename, pass the desired name to the --filename
flag. You can use the variables [[name]]
, [[handle]]
, [[text]]
, and [[id]]
in your filename, which will be replaced according to the following chart. The file extension .md
will also be added automatically.
Variable | Replacement |
---|---|
[[handle]] | The user's handle (the part that follows the @ symbol) |
[[name]] | The user's name |
[[id]] | The unique ID assigned to the tweet |
[[text]] | The entire text of the tweet (truncated to fit OS filename length restrictions) |
ttm <tweet url> --filename "[[handle]] - Favicon versioning".
# Tweet saved to JoshWComeau - Favicon versioning.md
If the file already exists, an error will be thrown unless you pass the -f
(--force
) flag to overwrite the file.
To save the tweet to a place other than the current directory, pass the location to the -p
(--path
) flag. If this path doesn't exist, it will be recursively created.
ttm <tweet url> -p "./tweets/"
# Tweet saved to ./tweets/JoshWComeau - 1213870628895428611.md
If you'd also like to record the number of likes, retweets, and replies the tweet has, pass the -m
(--metrics
) flag. This will save those numbers in the frontmatter of the file.
ttm <tweet url> -m
---
author: Josh ✨
handle: @JoshWComeau
likes: 993
retweets: 163
replies: 24
---
Want to really capture the entire tweet locally? You can pass the -a
(--assets
) flag to download all the tweet images as well, instead of just linking to the images on the web. If the tweet is ever deleted or Twitter is unavailable, you'll still have your note.
ttm <tweet url> -a
Tweet images will be automatically saved to ./tweet-assets
. If you'd like to save the assets to a custom directory, use the --assets-path
flag and pass in the directory.
ttm <tweet url> -a --assets-path "./images"
Nota bene: Unfortunately, there is currently not a way to save gifs or videos from tweets using the v2 API.
Using the --date_locale
option, you can pass a BCP 47 language code to have the date displayed in a specific locale. If you don't pass this option (or if you're using lower than Node 13), your computer's default locale will be used.
Finding a complete list of these language codes is difficult, but here's a short list of examples:
Tag | Language |
---|---|
en | English |
en-US | American English |
es-MX | Mexican Spanish |
ta-IN | Indian Tamil |
A more complete list can be found here: https://gist.github.com/typpo/b2b828a35e683b9bf8db91b5404f1bd1
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature
) - Commit your Changes (
git commit -m "Add a cool feature"
) - Push to the Branch (
git push origin feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE
file for details
Karey Higuera - @kbravh - karey.higuera@gmail.com
Project Link: https://github.com/kbravh/tweet-to-markdown