Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickangtc/337240051fdd3ab8485c57ae45b1c397 to your computer and use it in GitHub Desktop.
Save nickangtc/337240051fdd3ab8485c57ae45b1c397 to your computer and use it in GitHub Desktop.
Apple Automator script using JavaScript to generate a timestamp string in format YYYYMMDDHHMM
// To use JavaScript in Apple Automator, select 'Run JavaScript' action
// copy-paste this code into that action
// no need to have any other action -> output is printed automatically
function run(input, parameters) {
var now = new Date()
var year = now.getFullYear()
var month = now.getMonth() + 1
var day = now.getDate()
var hours = now.getHours()
var mins = now.getMinutes()
if (month.toString().length < 2) month = "0" + month
if (day.toString().length < 2) day = "0" + day
if (hours.toString().length < 2) hours = "0" + hours
if (mins.toString().length < 2) mins = "0" + mins
return `${year}${month}${day}${hours}${mins}`
}
@nickangtc
Copy link
Author

I used this to generate a unique time-based string for identifying notes in my zettelkasten note-taking system. Details: https://twitter.com/nickang/status/1229440171717922817

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