Skip to content

Instantly share code, notes, and snippets.

@DivineDominion
Created September 11, 2014 08:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DivineDominion/fe1d4d39baf45477a496 to your computer and use it in GitHub Desktop.
Save DivineDominion/fe1d4d39baf45477a496 to your computer and use it in GitHub Desktop.
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
@amelchi
Copy link

amelchi commented Nov 7, 2020

sorry for a late question... dummy perhaps
when I get to nvalt I get the date this way
Schermata 2020-11-07 alle 11 08 21
how to correct it to your date format?

TIA

@DivineDominion
Copy link
Author

@amelchi And you get this output when you run the script above? Because the current_date function actually composes a string of numbers manually. Yours looks like a system-formatted date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment