Results 1 to 7 of 7

Thread: Date/Time Key

  1. #1
    Join Date
    Oct 2013
    Beans
    5

    Date/Time Key

    I want to assign a custom keymap that inserts a Timestap as if I typed it out myself.

    Under Unity Ubuntu 12.10 LTS, I type keyboard into the Dash, then I click on "Keyboard" app, not "Keyboard Layout" that one doesn't appear to do what I wanted it to do. Then I click on the "Shortcuts" tab, go down to "Custom Shortcuts" and then click on the + symbol to add the following.

    Name: timestamp
    Command: echo -n "`date`"

    This didn't work for me, I don't know what command to put to make it work, please fix this problem for me it is quite an issue since I have no idea what command even means.

    echo -n "`date`" works in the terminal for me but my key doesn't work, I set it to using Ctrl+Alt+Space.

  2. #2
    Join Date
    Jun 2010
    Location
    London, England
    Beans
    6,958
    Distro
    Ubuntu Development Release

    Re: Date/Time Key

    I do not have the answer but I have tried to do this myself just now and it is my guess that the command is incorrect. That command in a terminal will echo or print these characters on the terminal screen 'date' The echo command put an echo or prints whatever characters we have between the quotation marks.

    What particular application do you wish to do this with? In Libreoffice we go to Insert>Fields and select either Date or Time or both.
    Last edited by grahammechanical; October 2nd, 2013 at 09:03 PM.
    It is a machine. It is more stupid than we are. It will not stop us from doing stupid things.
    Ubuntu user #33,200. Linux user #530,530


  3. #3
    Join Date
    Apr 2012
    Beans
    5,428

    Re: Date/Time Key

    You could do something like this, I think

    1. install xclip

    2. set the shortcut command to generate the date and copy it into the clipboard
    Code:
    sh -c 'echo `date` | xclip -selection clipboard'
    3. to insert the date into your current application, you can then press your shortcut key combo followed immediately by the application's paste shortcut e.g. Ctrl-v

    I just gave it a try and it seemed to work for me, at least into gedit and libreoffice writer

  4. #4
    Join Date
    Oct 2013
    Beans
    5

    Re: Date/Time Key

    Yes, thanksalot, that works very well for me!
    It is a little inconvenient to press both twice, do you know if I can make a command that includes keystrokes? Ctrl+Alt+SPACEBAR and then Ctrl+V.
    But otherwise I am exeedingly happy with it, was looking for a while until I bothered to ask in here, everything I found was overcomplicated.
    Thanks again! I'm unbelievably gratefull!
    Last edited by Kompftputer; October 2nd, 2013 at 11:15 PM.

  5. #5
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,344
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Date/Time Key

    you can add ; xdotool key ctrl+v inside the single quotes to automatically generate 'paste' signal. Alternatively if you used primary buffer with xclip you'd be able to paste with middle click (xdotool click 2).
    Personally i use xsel instead of xclip, it's shorter
    xsel -pi (put into primary buffer of middleclick)
    xsel -si (secondary)
    xsel -bi (clipboard ctrl+v)
    Last edited by Vaphell; October 2nd, 2013 at 11:19 PM.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  6. #6
    Join Date
    Oct 2013
    Beans
    5

    Re: Date/Time Key

    Okay.
    I have installed xdotool.
    This is my code
    Code:
    sh -c 'echo `date --rfc-3339=seconds` | xclip -selection clipboard'
    What do I do with it now? I don't understand anything else of what you posted, it's all alien to me.
    Where do I put what where?
    I have installed xsel now. I hope it's not just for office suites as in excell, I want to paste timestamps everywhere, all over the place, upside-down even. Web Browsers and Filenames, I dunno where else but just assume if it exists I want it timestamped on.
    Last edited by Kompftputer; October 2nd, 2013 at 11:33 PM.

  7. #7
    Join Date
    Oct 2008
    Beans
    3,509

    Re: Date/Time Key

    Quote Originally Posted by Kompftputer View Post
    Okay.
    I have installed xdotool.
    This is my code
    Code:
    sh -c 'echo `date --rfc-3339=seconds` | xclip -selection clipboard'
    What do I do with it now? I don't understand anything else of what you posted, it's all alien to me.
    Where do I put what where?
    I have installed xsel now. I hope it's not just for office suites as in excell, I want to paste timestamps everywhere, all over the place, upside-down even. Web Browsers and Filenames, I dunno where else but just assume if it exists I want it timestamped on.
    I can't get anything to work with keyboard shortcuts whether I put in a command or the path to a script in unity 13.04.
    Edit: Found custom shortcuts had been disabled somehow.
    Maybe through installing another desktop.
    Check the output of this command...
    Code:
    gsettings get org.gnome.settings-daemon.plugins.media-keys active
    If it returns false, set back to default(true) with this command....
    Code:
    gsettings reset org.gnome.settings-daemon.plugins.media-keys active
    Should now be able to set a custom keyboard shortcut.
    Use this as the command in the custom shortcut comand box
    Code:
    sh -c "sleep 1 && xdotool type $(date --rfc-3339=seconds)"
    198.jpg
    ----------------------------------------------------------------------


    This command works with easystroke(mouse gestures) though....
    Code:
    xdotool type $(date --rfc-3339=seconds)
    ...and the same command with a delay so your keypress doesn't interfere, works with the compiz commands plugin (bound to ctrl+alt+d)...
    Code:
    sleep 1 && xdotool type $(date --rfc-3339=seconds)
    Attached Images Attached Images
    Last edited by stinkeye; October 3rd, 2013 at 08:06 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •