본문 바로가기

소프트웨어 개발/macOS

How to automatically paste today's date with keyboard shortcut? (ex: 2018_05_19 23:15:05)

  1. Create new: Services
  2. Services receives no input in any application
  3. Use the search to find and add action: Run Applescript
    • Copy and paste the following to the field on the right:
tell application "System Events"
  set _Date to (current date)
  keystroke ¬
    (year of _Date as text) & "_" & ¬
    text -2 thru -1 of ("00" & ((month of _Date) as integer)) & "_" & ¬
    (day of _Date as text)  & " " & ¬
    text -2 thru -1 of ("00" & ((hours of _Date) as integer)) & ":" & ¬
    text -2 thru -1 of ("00" & ((minutes of _Date) as integer)) & ":" & ¬
    text -2 thru -1 of ("00" & ((seconds of _Date) as integer))
end tell

Note that the day will not have a leading zero like the month does. If you want that, you could replace the line with: (day of _Date as text) with: text -2 thru -1 of ("00" & ((day of _Date) as integer))

  1. Save with: Cmd + S. Give it a name you can remember in the next step.
    • If you simply use the Save command ( Cmd + S ) instead of Save as... the Service file is automatically put in the right place.



The next step would be to define a shortcut for the service you just made.

Use either one of these methods:

  1. My first recommendation would be Services Manager.

    • If you install and open it, all you need to do is search for the service you just saved before and double click the key area (This I have to admit isn't super obvious, because the area isn't well defined. You can probably see other shortcuts for other services, which kinda indicates that this is where you can change the shortcut.)
    • Its default path is /Applications/Utilities/Services Manager.app
    • This app is incredibly useful for managing Service shortcuts, but if this is just a one time thing, you can just use the method described below, which doesn't require extra applications to be installed.
  2. Another way would be to go to mac System preferences > Keyboard > Shortcuts > Servicesand then find the service you saved before. You should find it at the bottom area of the list. Then you just double click the none text on the right side of the service name and give it a shortcut.


'소프트웨어 개발 > macOS' 카테고리의 다른 글

Softwares on my macOS v0.2  (0) 2018.05.22