High Speed Data Entry for Notion.so

This is a tutorial for users of Apple Macintosh computers and the Notion 
personal information management web application. The result of this integration
allows me to type a command key combination to get a text entry input box where
I can type a keyword and a message. The message is sent to a Notion database.

This data entry is very, very quick, no longer than a couple of seconds. It allows
the capturing of ideas or notes without distracting from the current task at all. I
use it for todo items and other quick inspirations when I am deep in concentration on 
something else. The message is saved in a useful way in no time at all and I am not 
moved out of the zone.

This is, however, a fairly advanced technique. As an experienced programmer, I figured
this out in a few hours. I would expect that I could implement this tutorial in fifteen
or twenty minutes. If you are not like me, it might take you longer.

This is an integration using three elements:

Notion.so is a personal information manager that runs in the cloud.

NodeJS is a language interpreter for Javascript.

Alfred is a productivity tool for Macintosh.

None of these are small programs. It's not necessary to master any of them for this
purpose but if there were ever any famous last words, those are them.

Good luck.

TQ White II

ps, I'm generally inclined to be helpful. If you have problems (or notice an error
on this page), reach out at this address.



Make sure to have an informative subject line and to not be spammy. I have an aggressive
spam filter.

1) Get Alfred. Pay for Powerpack. Make it work.

https://www.alfredapp.com
2) Get NodeJS. Verify function by typing "node --version" and seeing something sane.

https://nodejs.org/en/download/
3) Make an API integration in Notion. Connect it to your database. Copy the database ID and API key.

https://developers.notion.com/docs/getting-started
4) Create a NodeJS application file based on this.

#!/usr/local/bin/node
'use strict';

//CONSTANTS ============================================================

const auth = 'secret_*******************************************';

const databaseIds = {
    atom'********************************',
    tv'********************************'
};

//SENDING FUNCTION ===================================================

const sendToNotion = async function(targetmessageItem) {
    const { Client } = require('@notionhq/client');
    
    // Initializing a client
    const notion = new Client({
        auth
    });
    
    const database_id = databaseIds[target];
    async function addItem(text) {
        try {
            const response = await notion.pages.create({
                parent: { database_id },
                propertiesmessageItem
            });
            console.log(response.url);
        } catch (error) {
            console.error(error.body);
        }
    }
    
    addItem(messageItem);
};

//EXECUTION ============================================================

sendToNotion('atom', {
    title: {
        title: [
            {
                text: {
                    contentprocess.argv[2]
                }
            }
        ]
    }
});

Some Notes:

a) This is simplified from my real setup. I use this for a couple of databases, atom and tv, as you can see in the code. Though I verified that
this works, in my real code, it is a structured app with sendToNotion() in it's own module so I can have use it for the two different calls.

b) If you are Terminal savvy, you can do 

	chmod +x /path/to/file.js
	
	
to operate this. That would allow you to do something like

	/path/to/file.js "message for my Notion database"
	

and it would work. This, obviously, is good for testing and getting it done.

c) You will need a place on your disk for this code to reside. I suggest that you create 
a folder in your home directory named 'bin' with another directory inside called 'notionAccess'.

You can do that with this command:

mkdir -p ~/bin/notionAccess


To make this work, you will (assuming that you have NodeJS installed correctly) be able to type:

cd ~/bin/notionAccess;        #use this as your working directory
npm init;                     #leave the main file as index.js, this is where you will put the above code.
npm i @notionhq/client;       #this will get the Notion access library
touch index.js;               #this creates the file
chmod +x index.js;            #make it executable for testing
open -a Textedit index.js;    #this will open the file for editing, you can paste the above code into it


Once you have put in your database ID and API key, it should work when you type:

~/bin/notionAccess/index.js "Message for Notion Database";


It will either show you a URL or an error. If it's a URL, it's in your database. 

If it's an error, good luck.

5) Wire it up to Alfred.

Do not bother with this until you have succeeded in sending a message to Notion 
from the Terminal as described above.

Here are the basic steps:

1) Open Alfred, choose Workflows and at the bottom of the Workflows list, click the +
and choose Blank Workflow.

2) Right click in the resulting window and choose Inputs->Keyword. A panel will show up
that lets you set the triggering word for this action (I use 'log'.). Other things, too, that I rarely
bother with.

3) Right click again and choose Actions->Run Script. On the resulting panel,
choose Language->External Script. Fill in the path. (You can drag the file, index.js, 
to the panel.) The code in that file should appear in the panel.

4) Drag an arrow from the right side of the Trigger icon to the left side of the
Action icon. You will end up with something like this:



5) There is a debug icon in Alfred that will show you error messages. Good luck.

FINALLY...

Activate Alfred (its default is opt-spacebar) and type, eg,




And it should appear in your Notion database in less than two seconds.