Skip to content

Instantly share code, notes, and snippets.

@astoilkov

astoilkov/Paste Hook.md Secret

Created Mar 15, 2021
Embed
What would you like to do?

Paste Hook

⚠️ Nota extensibility is highly experimental. You can experiment with it and give us feedback but expect a lot of changes.

With the paste hook you can modify the text that will be pasted in Nota.

You can open the hook for the current workspace by going to the Command Palette...(⌘⇧P) and selecting "Open Paste Hook". By default Nota creates a hook that does nothing:

#!/bin/bash
# @parameters clipboardText

@parameters

In the previous example you could have noticed the @parameters clipboardText comment. This comment tells Nota to pass the current clipboard contents as a first argument to the script.

You can pass a few different values to the paste hook:

  • clipboardText – the text contents of the clipboard
  • selectedText – the currently selected text, empty string if no text is selected
  • file – the path to the currently opened file
  • workspace – the path to the currently opened workspace

To tell Nota which values to pass to the script add a @parameters decorator with the parameters separated by spaces: @parameters selectedText file workspace. This will make: $1 the selected text, $2 the currently edited file and $3 the path to the currently opened workspace.

Ideas for hooks

  • Privacy URLs – A lot of URLs have tracking data. Why not remove the tracking data for your most common URLs?
  • Paste URL over text – Create a markdown link when pasting an URL and there is a text selected. A small productivity hack.
  • Format pasted text – You may want to strip indents, replace a specific word with another, replace an URL with a markdown link.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment