Create Files

Create a Text File

// Name: Create a Text File
import "@johnlindquist/kit"
let filePath = await path() // Select a path that doesn't exist
let exists = await pathExists(filePath)
if (!exists) {
await writeFile(filePath, "Hello world")
} else {
await div(md(`${filePath} already exists...`))
}

Open create-a-text-file in Script Kit

Update a Text File

// Name: Update a Text File
import "@johnlindquist/kit"
let filePath = home(`my-notes.md`)
// `ensureReadFile` will create the file with the content
// if it doesn't exist
let content = await ensureReadFile(filePath, "Hello world")
await editor({
value: content,
onInput: _.debounce(async input => {
await writeFile(filePath, input)
}, 200),
})

Open update-a-text-file in Script Kit

Discuss Post