Docs
Save Hook
The save hook lets you run code every time Nota auto-saves a file:
- Open the Go → Command Palette... ⇧⌘p and search for "Open Save Hook". This will open the save hook with some instructions inside.
- You can now write to the saved file (e.g. format the text) or work with an external system (e.g. Git).
Here is a sample save.js
hook that ensures the file ends with a newline:
#!/usr/bin/env node
// @parameters file
const fs = require('fs')
const filePath = process.argv[2]
const text = fs.readFileSync(filePath, 'utf8')
if (!text.endsWith('\n')) {
fs.appendFileSync(filePath, `\n`)
}
Save hook is located at path/to/your/workspace/.nota/hooks/save.extension
(e.g. ~/Dropbox/Nota/.nota/hooks/save.js
).
@parameters
If you aren't familiar with the @parameters
syntax, read the article first.
@parameters
tells Nota which values to pass to the script:
file
– the path to the currently opened fileworkspace
– the path to the currently opened workspace
Ideas for hooks
- Ensure the file ends with a new line
- Strip trailing whitespace at the end of each line
- Create a Git commit for each day and automatically
git push
- Backup your files
- Instead of a file watcher
git add .
to track Git changes