Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AppleScript to rename notes in nvALT with the Zettel ID and a title of your choosing. Also inserts the information as a header into the note.
-- Extend "current date"
script FormattedDate
property parent : current date
on twoDigitDisplay(aNumber)
set multiplier to 10 ^ 2 #howManyDigits
return "" & (text 2 thru 3 of ((multiplier + aNumber) as string))
end twoDigitDisplay
end script
to current_date()
tell FormattedDate to get "" & ¬
(it's year as text) & ¬
(twoDigitDisplay(it's month as integer)) & ¬
(twoDigitDisplay(it's day)) & ¬
(twoDigitDisplay(it's hours as integer)) & ¬
(twoDigitDisplay(it's minutes))
end current_date
on run {input, parameters}
set theDate to current_date()
display dialog "Title" default answer ""
set theTitle to (text returned of result)
set theZettel to theDate & " " & theTitle
--- You can add a second line with "Tags: " in here, for example
set theHeader to "" & theZettel & "
tell application "nvALT" to activate
tell application "System Events"
--- Save the old clipboard
set currentClipboard to the clipboard
--- Paste the header
set the clipboard to theHeader
keystroke "v" using command down
delay 0.3
--- Rename the file (Cmd-R) and paste in the title
keystroke "r" using command down
set the clipboard to theZettel
keystroke "v" using command down
delay 0.3
--- Move back to the editing pane and restore the clipboard
keystroke tab
delay 1
set the clipboard to currentClipboard
end tell
return theHeader
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.