How to insert tomorrows date?

Asked by Cliff Karlsson

How do I make sikuli type tomorrows date to a field? like: 2012-05-10

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

hava a look at Python's datetime module.
http://docs.python.org/library/datetime.html

Revision history for this message
RaiMan (raimund-hocke) said :
#2

in case you are new with Python:

import datetime
print datetime.date.today() + datetime.timedelta(1)

Revision history for this message
Cliff Karlsson (silvercircle666) said :
#3

Thank you, I know it is really very basic but how do I get the date to be printed in notepad for example? Right now I can only see the date in the Sikuli message -field.

I tried playing around with type instead of print but I can't get it to work.

Revision history for this message
j (j-the-k) said :
#4

if the notepad-program is open and focused, a simple type(mydate) should do the trick.. ?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

here is a template for what j-the-k supposed:

import datetime
tomorrow = datetime.date.today() + datetime.timedelta(1)
openApp("notepad") # open a new notepad window and give focus
type(str(tomorrow)) # has to be casted to String

Take care: If type() in many cases does not type the expected characters, you can use paste() instead (see faq 933)

If you want to have the date in different formats:
http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior

Revision history for this message
RaiMan (raimund-hocke) said :
#6

This is more secure, to give the editor window some time to get ready for input:

import datetime
tomorrow = datetime.date.today() + datetime.timedelta(1)
openApp("notepad") # open a new notepad window and give focus
wait(2)
type(str(tomorrow)) # has to be casted to String

Can you help with this problem?

Provide an answer of your own, or ask Cliff Karlsson for more information if necessary.

To post a message you must log in.