# SendPreview-2-Notion

SendPreview-2-Notion sends one or more image files from macOS Preview/Share Sheet into a Notion database. For each image it prompts for a page title, creates a database page, uploads the file via Notion file uploads, and appends the uploaded file as an image block.

Version: 1.0
Author: Bert Mahoney

## Requirements

- macOS Ventura or newer recommended
- A Notion internal integration with edit access to the target database
- `curl` and `osascript` (included with macOS)
- `jq` (`brew install jq`)

## Quick install

```bash
./scripts/install.sh
```

The installer copies `scripts/send_to_notion_image.sh` to `~/.local/bin/` and creates a private config template at `~/.config/sendpreview-2-notion/.env` if one does not already exist.

Edit the config file before first use:

```bash
nano "$HOME/.config/sendpreview-2-notion/.env"
```

Required values:

```bash
NOTION_TOKEN="ntn_PASTE_YOUR_TOKEN_HERE"
NOTES_DB_ID="PASTE_YOUR_DATABASE_ID_HERE"
```

Optional values if your database schema differs:

```bash
PROP_TITLE="Name"
PROP_TYPE="Type"
TYPE_VALUE="Image"
NOTION_VERSION="2025-09-03"
```

## Manual install

```bash
brew install jq
mkdir -p "$HOME/.config/sendpreview-2-notion" "$HOME/.local/bin"
cp .env.example "$HOME/.config/sendpreview-2-notion/.env"
cp ./scripts/send_to_notion_image.sh "$HOME/.local/bin/send_to_notion_image.sh"
chmod +x "$HOME/.local/bin/send_to_notion_image.sh"
```

Then edit `~/.config/sendpreview-2-notion/.env` with your real Notion token and database ID.

## Notion setup

1. Open Notion settings and create an internal integration.
2. Copy the integration token; it starts with `ntn_`.
3. Open the target database.
4. Share the database with your integration and grant edit access.
5. Copy the database ID from the database URL.

Example database URL:

```text
https://www.notion.so/workspace/164ffa30cf0b81b1929ae59d8b6afabb?v=...
```

Database ID:

```text
164ffa30cf0b81b1929ae59d8b6afabb
```

The database must have:

- A title property matching `PROP_TITLE` (default: `Name`)
- A select property matching `PROP_TYPE` (default: `Type`) with an option matching `TYPE_VALUE` (default: `Image`)

## Configure the macOS Shortcut

1. Open the Shortcuts app.
2. Create a new shortcut named `Send Image to Notion`.
3. Add a `Run Shell Script` action.
4. Set input to be passed as arguments.
5. Use this script body, replacing `YOUR_USERNAME` if needed:

   ```bash
   /Users/YOUR_USERNAME/.local/bin/send_to_notion_image.sh "$@"
   ```

6. Enable `Use as Quick Action`.
7. Enable `Show in Share Sheet`.
8. Set it to receive images.

## Usage

From Preview:

1. Open an image in Preview.
2. Click Share.
3. Select `Send Image to Notion`.
4. Enter a page title when prompted.

From Terminal for smoke testing:

```bash
~/.local/bin/send_to_notion_image.sh /path/to/test-image.jpg
```

## Offline validation / dry run

You can validate local dependencies, file handling, MIME detection, and generated Notion JSON without GUI prompts, real Notion credentials, or network calls:

```bash
~/.local/bin/send_to_notion_image.sh --check-deps
~/.local/bin/send_to_notion_image.sh --dry-run /path/to/test-image.jpg
```

For repeatable tests, set a non-interactive title:

```bash
SENDPREVIEW_TITLE="Test page title" ~/.local/bin/send_to_notion_image.sh --dry-run /path/to/test-image.jpg
```

Repository maintainers can run the bundled harness, which also checks installer behavior plus `--help`/unknown-option handling:

```bash
tests/dry_run.sh
```

## Troubleshooting

- `401 unauthorized`: token is invalid, expired, or copied incorrectly.
- `404 object_not_found`: database is not shared with the integration, the ID is wrong, or the integration lacks access.
- `jq not found`: run `brew install jq`.
- Page creation fails with a property error: update `PROP_TITLE`, `PROP_TYPE`, or `TYPE_VALUE` in `~/.config/sendpreview-2-notion/.env` to match the Notion database schema.

## Security notes

Do not commit a real `.env` file or Notion token. This repository includes `.env.example` only.
