Last Updated: February 25, 2016
· pickachu

How to copy current time to clipboard with shellscript in OSX


date +"%H:%M" | tr -d '\n' | pbcopy


Part 1:

Outputs the date in the format.

date +"%H:%M"

The date command uses a format string (don't forget the leading + sign) with a canonical representation as:

cc      Century (either 19 or 20) prepended to the abbreviated year.
yy      Year in abbreviated form (e.g., 89 for 1989, 06 for 2006).
mm      Numeric month, a number from 1 to 12.
dd      Day, a number from 1 to 31.
HH      Hour, a number from 0 to 23.
MM      Minutes, a number from 0 to 59.
ss      Seconds, a number from 0 to 61 (59 plus a maximum of two leap seconds).

Part 2:

Delete the newline character from the standart input.

tr -d '\n'

The '-d' option simply gets the input string and delete character for it. Other options for the tr command include translating strings! What a useful command.

Part 3:

The pbcopy takes the standard input and places it in the general clipboard, since no clipboard was specified.


Another useful is pbpaste, that just outputs the content of the general clipboard if no one is specified.

How is this useful?

Here at my company we use this to easily store our start and end times of pomodoros while working:


Then paste it on our Timesheet:


Giving us a little more of time and focus when pomodoros finish.

What do you think? How do you automate your time tracking insertion?

Just drop a comment, i would be glad to know