Move selected text to a note within a directory #169
Answered
by
johnlindquist
classicrob
asked this question in
Q&A
Move selected text to a note within a directory
#169
Replies
|
Great idea! I'm heading out for my 2nd vaccine shot, but I'll put together a script demo for you this afternoon |
0 replies
|
Here's what I came up with. I couldn't decide between this solution (listing all the files twice, once for each action) or spitting it into a //Shortcut: opt x
//I haven't decided on the final api for a keyboard lib, use this for now:
let command = async key =>
await applescript(`
tell application "System Events"
keystroke "${key}" using command down
end tell`)
//-----------------------------------------------------------------------
let NOTES_PATH = await env("NOTES_PATH", {
placeholder: "Set env for NOTES_PATH",
})
let { note, key } = await arg("Select note", async () => {
let notes = await readdir(NOTES_PATH)
return notes.flatMap(note => {
let copyTo = {
name: note,
description: `copy`,
value: {
note: path.join(NOTES_PATH, note),
key: `c`,
},
}
let cutTo = {
name: note,
description: `cut`,
value: {
note: path.join(NOTES_PATH, note),
key: `x`,
},
}
return [copyTo, cutTo]
})
})
//Hide so the keyboard shortcut can focus on the app under the prompt.
// This will also be an interal API in the future
send("HIDE_APP")
await command(key)
await appendFile(note, await paste())
edit(note) |
4 replies
Answer selected by johnlindquist
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

I'm curious - how straightforward would it be to create a global sort of "move block" function with script kit? I'm imagining highlighting a text selection, pressing a keyboard shortcut, cutting that selection, searching through files within my notes directory to find the specific file I want to add it to, and then appending it to the bottom. Ideally, at the point of insertion, I decide whether to leave a copy of the text in the original location or whether it is just fully moved to the new location.
Thank you!
Here's what I came up with. I couldn't decide between this solution (listing all the files twice, once for each action) or spitting it into a
arg("Select note")and aarg("Select command"). But hopefully this should get you started with whatever you decide.Install testing-cut-to-file