pythonkeyboard-shortcutskey-bindingsarchlinuxautokey

set the cursor inside the function "keyboard.send_keys"


I'm trying to set a shortcut in order to send an output like this: [DATE]_[thecaret/cursor].somethinelse

For example: 18-02-18_[myCursorHere].png

This is the script for AutoKey under linux:

output = system.exec_command("date +'%Y%m%d'+'_$(cursor).png'")
keyboard.send_keys(output)

But the result is literally this one:

20180218+_$(cursor).png

Do you have any idea how to insert the cursor in the righ place using this script?

PS: Autokey also let me use the "phrase" function, where there are some macros, as "insert date" and "insert cursor" but I can't get it work. In that case the script is this one:

test <date format='%d-%m-%y'><cursor> something here

nothing happens (actually my text editor goes freeze)


Solution

  • found the solution (using "time" instead of date command is better)

    import time
    t = time.strftime("%d.%m.%Y")
    length = "-.pdf"
    keyboard.send_keys(t+length)
    keyboard.send_key("<left>", len(length)-1)