AppleScript to type current date?

I’ve found that the only reason I use any of the text replacement tools is to type the current date, like 2020-04-20_. Does anyone know of a way to do this with an AppleScript service or something similar?

Update: This was poorly worded, is there a way to do this with pure AppleScript? No other apps? Or an Automator “Quick Action”?

Text expansion software does that very readily if you have TextExpander, Typinator and such.

Right, and I’ve had them all over the years, using Keyboard Maestro for it now, but it seems kind of like a waste to run an entire app just to type the date every now and then. That’s just the trend I’ve noticed over the past decade or so with my use, I know a lot of other folks get tons more use out of the utilities. YMMV.

You can also get the same functionality with Alfred’s text expansions if you use that.

Or if you have some way of getting it you can use that same shell script I put in the macro

2 Likes

Cool, mine is almost the same:

What I’m saying is this is a valid AppleScript

do shell script "date +\"%Y-%M-%d\""
2 Likes

Ah, :bulb: Got it, I think I can sort something out here.

1 Like

Y’all, this was so simple.

  1. Create a new Quick Action in Automator.
  2. Set it so it receives no input in any application
  3. Add one action to “Run Shell Script”
  4. Run this command: echo "`date +"%Y-%M-%d"`_"
  5. Save the Quick Action, name it “Date Stamp” or whatever
  6. Open Keyboard Preferences and add a custom shortcut, mine is ⌃⌘⌥=
  7. Hit that hotkey in any standard Mac app and there it is.

Ok, so not “Soooo” simple, but still, not bad!

4 Likes

This isn’t what you asked for, but I love Brett Terpstra’s Make A Date. Looking back at it, I guess it uses Keyboard Maestro, which I have (and use for a lot of stuff besides text expansion). But there’s nothing like being able to just type >>tues< and get next Tuesday’s date…

2 Likes

I guess it is AppleScript sprinkled with shell script. I also use this method many times. If you want 100% AppleScript you can do it like this:

set DateString to DateStamp()
-- DateString will be 2021-04-24_

on DateStamp()
	tell (current date) to tell (year * 10000 + (its month) * 100 + day) as string to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7 thru 8 & "_"
end DateStamp
1 Like

This is perfect, thanks!