How to add a 'datestamp'

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

How to add a 'datestamp'

26 Sep 2018, 06:25

Some months ago I tried to study up on AutoHotKey for a very simple task but failed to understand or get it. I believe it is very simple so not getting it under my own steam, I will blame my advanced years.
I have just registered in an effort to see if I can get an answer to my problem. (have done a search on datestamp and going back trying again)

From what I do understand it seems to me that my task is very simple and AutoHotKey will do the job easily.

Here is my little problem:

I would like to datestamp my file and folder names, should say precede my file and folder names with a form of date stamping, like 180926- (yymmdd-)

Each day over and over again I type the 'datestamp' then the filename/folder name (followed by ENTER) the novelty of all that repetitive stamping and then getting it wrong occasionally has worn off.

I would like to just be able to hit a hot key, if possible use one of the F keys or on this keyboard I have 19 multimedia keys that I don't use, have not really looked at what they do.

As an example, "File Save As"-> hotkey ->Notes-for-parts-processing.glk ENTER

Where the ".glk" is an extension code for search purposes

The result: 180926-Notes-for-parts-processing.glk

How do I go about setting up AHK
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to add a 'datestamp'

26 Sep 2018, 07:42

Code: Select all

F1::
	FormatTime timestamp, A_Now, yyMMdd
	Send % timestamp
return
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: How to add a 'datestamp'

26 Sep 2018, 07:44

So I don't know about the file save as part but I can help with the hotkey part of it.
first we will start with the hotkey

Code: Select all

^f::   ;This is control + f to trigger the hotkey
FormatTime, Output,, yyMMdd	;Here we format the time, the Output is the variable output, the next part (which is blank) is the input (which by default uses the current time), and the last part is the specific part of output we want, ie 2 digit year, 2 digit month, 2 digit day
Send, % Output "-Notes-for-parts-processing.glk"	;Here we send the data inside the Output variable followed by the rest of the statement we want, notice the % at the start followed by a space to represent that we are sending variables. For litteral text we want to place "" around it so it knows we want that exact string
Send, {Enter}
Return
Note that the send will only work if that field is focused.
Last edited by MannyKSoSo on 26 Sep 2018, 12:19, edited 1 time in total.
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

26 Sep 2018, 09:18

Thank you both, I can understand the first line in both replies and will try and decode the rest.
F1:: ie hot key is F1
^f:: ie hot key selection is ctl-f
That will do me for tonight, tomorrow I will look at the rest when I have re-read the start tutorial. Need to do that because of short term memory.
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

27 Sep 2018, 00:24

Ouch, I did not think properly. I downloaded both scripts above and renamed first one AutoHotkey64.ahk and the second one as AutoHotkey.ahk, they both work in a fashion. Will return to that.

The main thing now I have lost my normal search with ctl-F and also the applications F1 key macro, I did expect that this might happen. I would just restart and assume this would reset the keys to default.

I am curious however, is it possible to reset the hot keys with ahk commands? Have a vague recollection I may have seen such but do not remember. A quick search has not shown result yet?

Changing to one of the extra 19 Multimedia keys on this "Internet Keyboard" that is the model number. How do I go about checking how they will work in ahk? Is there a way to pick up and reveal keycodes or such via ahk and then turn them into 'hot keys'

Added Later
A few minutes later I stumbled over the list of Multimedia Keys so now my question is to make a hotkey out of the "BACK" key, is that just Browser_Back:: ? Almost seems too simple :)
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to add a 'datestamp'

27 Sep 2018, 03:18

yes, it could be that simple. if it doesnt work, u can try defining a hotkey using the key's virtual key or scan code
see thsi guide here: https://autohotkey.com/docs/KeyList.htm#SpecialKeys
make sure u add #InstallKeybdHook somewhere in the script
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

27 Sep 2018, 04:44

Yes it does work so now the first suggested script looks like this:

Code: Select all

Browser_Back::
	FormatTime timestamp, A_Now, yyMMdd-
	Send % timestamp
return
So when I press the "Browser_Back" key, wherever the focus is, like here: 180927- that takes care of the filename/folder name "header".

How do I input the 'body of the filename, which varies each time, to the ahk process and followed by the extension .glk which will be fixed in this case.

As it is it saves me 6 extra keystrokes, the script complete result should be: 180927-{whatever new name}.glk

How do I input a string to the process in this case (I am keen to learn)

swagfag
The link you gave, it looks very interesting, when I know more I will experiment with the rest of the Multimedia keys, presently I think it is a bit over my head but I understand the theory.
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

27 Sep 2018, 05:07

MannyKSoSo
I have allocated your script to run as AutoHotkeyU32.ahk, still struggling to get my head around using the default script option, but good fun.
By now I had figured out the connection to some of the keys on the multimedia key range on this keyboard, beauty with few extra dedicated keys to use.
So here I am using the Browser_Forward key, and it works almost like my intention.

Code: Select all

Browser_Forward::   			
FormatTime, Output,, yyMMdd
Send, % Output "-Notes-for-parts-processing.glk"	
Send, {Enter}
Return
The result of this script on my machine is: 180927Notes-for-parts-processing.glk the script is 'static naming' at present, looking for interactive dynamic operation.

Looks like I need to know about input strings to the process to get following: 180927-{variable input string each run}.glk

Question how can I make the script stop and wait for me to input the 'filename string' then complete by adding the .glk and terminate?
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: How to add a 'datestamp'

27 Sep 2018, 07:09

So you could do something like this

Code: Select all

Browser_Forward::   			
FormatTime, Output,, yyMMdd-
Send, % Output
KeyWait, . ;After the code sends the Output variable it will wait for you to press . so as it can write the rest of the extentsion
Send, glk
Send, {Enter}
Return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to add a 'datestamp'

27 Sep 2018, 07:17

Code: Select all

Browser_Back::
	FormatTime timestamp, A_Now, yyMMdd-
	Send % timestamp ".glk{Left 4}"
return
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

27 Sep 2018, 20:52

MannyKSoSo

The 'Keywait' does not seem to have any effect on my system, I tried a couple of other characters, Control and 'a' just following some leads by searching. Then I remembered reading about Keyhooks and following some pointers I arrived at how to check for Keyhook and see the following for your script.

The script does not waitjust prints: 180928-glk
Not sure what is going on, made think that perhaps following needed: #InstallKeybdHook

If I interpret correct the following is indicating that no user input took place (I did not get a chance) the question is why, I am using a win32 Professional (Actually I thought it was a windows 64 but I have experimented a lot with both in the past months so I have probably got myself confused)

As I wrote previously I run both, ie the AutoHotkeyU32 and 64 at the same time but with two different scripts? Am I breaking some rule here, was even thinking using the *A32 for a 3rd instance. (Just showing my ignorance and following the principle "What if I try this ----" until something barks at me :D
Script lines most recently executed (oldest first). Press [F5] to refresh. The seconds elapsed between a line and the one after it is in parentheses to the right (if not 0). The bottom most line's elapsed time is the number of seconds since it executed.

---- C:\Users\Aurak\AHK-gert\AutoHotkeyU32.ahk
004: Return (11.48)
005: FormatTime,Output,,yyMMdd-
006: Send,Output (0.11)
007: KeyWait,a
008: Send,glk (0.05)
009: Send,{Enter} (0.02)
010: Return (29.62)
005: FormatTime,Output,,yyMMdd-
006: Send,Output (0.11)
007: KeyWait,a
008: Send,glk (0.05)
009: Send,{Enter} (0.02)
010: Return (321.77)

Press [F5] to refresh.
Having installed Keyhook :

Code: Select all

;MannyKSoSo  suggested this,  https://autohotkey.com/boards/viewtopic.php?t=56362
;
Browser_Forward::  
#InstallKeybdHook 			
FormatTime, Output,, yyMMdd-
Send, % Output
KeyWait, a 
Send, glk
Send, {Enter}
Return
I think I have moved into to deep waters for me because this do not appear to have the desired action, I expected to see something about Keyhook. I have better wait and see now what response I get from Forum before I get even deeper in trouble.
Script lines most recently executed (oldest first). Press [F5] to refresh. The seconds elapsed between a line and the one after it is in parentheses to the right (if not 0). The bottommost line's elapsed time is the number of seconds since it executed.

---- C:\Users\Aurak\AHK-gert\AutoHotkeyU32.ahk
004: Return (9.36)
006: FormatTime,Output,,yyMMdd-
007: Send,Output (0.11)
008: KeyWait,a
009: Send,glk (0.05)
010: Send,{Enter} (0.01)
011: Return (78.20)

Press [F5] to refresh.
Added later when I finally figured out how to use KeyHistory properly

When hot key is used, the corresponding KeyHistory"
A7 169 u 0.00 Browser_Forward
4C 026 i d 0.01 l
4C 026 i u 0.00 l
4B 025 i d 0.02 k
4B 025 i u 0.00 k
0D 01C i d 0.02 Enter
0D 01C i u 0.00 Enter
74 03F d 6.16 F5 C:\Users\Aurak\AHK-gert\AutoHotkeyU32.ahk - AutoHotkey v1.1.29.01
Press [F5] to refresh.
Then I commented out some of the lines, following should wait before adding the 'glk' but it does not, shows immediately glk
Looks like Keywait is ignored??

Code: Select all

Browser_Forward::  
; #InstallKeybdHook 			
; FormatTime, Output,, yyMMdd-
; Send, % Output
KeyWait, a 
Send, glk
; Send, {Enter}
Return
Last edited by starling22 on 28 Sep 2018, 02:50, edited 3 times in total.
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

27 Sep 2018, 20:58

swagfag

The result of your script suggestion is now :180928-.glk(Left 4)

Interestingly, if it was supposed to have waited for input it would almost be correct. My head is spinning, I think it is time to go and do some gardening for change of mind. :)
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: How to add a 'datestamp'

28 Sep 2018, 07:19

I have tested and found the same issue, however I have tested this version and it should work for you

Code: Select all

Browser_Forward::
FormatTime, Output,, yyMMdd-
Send % Output
Input, Var, V, .
Send, glk
Send, {Enter}
Return
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to add a 'datestamp'

28 Sep 2018, 07:28

FYI:

Code: Select all

KeyWait, a
waits until a is not pressed down.
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

28 Sep 2018, 09:21

MannyKSoSo
It is very late here, but I confirm it does work, when I posted my previous entry I started thinking about wht other options and what came to mind was "Input" but I did not get around to check, so I ma rather happy that I was thinking in the right direction.

I am thinking up a few improvements already, will be back
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

29 Sep 2018, 07:26

just me
thank you for your post. I looked at the information at: https://autohotkey.com/docs/commands/KeyWait.htm

"Waits for a key or mouse/joystick button to be released or pressed down."

My understanding is that the following

Code: Select all

KeyWait, a
Used in a script, the script will stop running waiting for a string to be typed and terminated by pressing 'a' key in this case, it does not really matter if termination takes place o the down or the up move of the key. The script simply doe not stop and wait for any input, just completes the script, in this case adding 'glk'. I tested 3 different cases of terminator character.

The use of the 'Input' statement does work in the manner of stopping and I can add the string making up a filename and in this case hitting '.' will terminate the string and add 'glk such as:

180929-just me.glk

I am thinking about how I can make it even easier to to set up a new file specifically in the <user>Documents directory Independent of where the mouse pointer is at the time

For example like:
Bring focus to "Q-dir" my filemanager
Move to the Documents directory
Open a new file
Type in the string for file name preceded by todays date {this line is what I have already for general use where the mouse pointer focus is at present.}

It is easy to specify but more complicated I think to actually script.
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

17 Apr 2019, 04:25

I am reviving this thread after having used the simple 'date' stamping which is very helpful for me. I have found that often I download files, datasheets via Firefox to the Downloads folder and loose track of what I have got there. Lately I have tried to follow up instantly with going to the downloads folder via the direct link to the file downloaded and try to 'date' stamp the front of the file name. With my limited knowledge I have hit a brick wall.

1.. A file is already highlighted
2.. Rename the file, adding date stamp at the beginning of the name
3.. Add the present 'date' and a -, ie "date-"
4.. Then ENTER

Manually I can do:
The highlighted file "xxxxxxx.yyy"
Rename file {F2} key
Go to front of name, {Home} key
Insert the "date-"part
ENTER

Result renaming file
"190417-xxxxxxx.yyy"

My ahk attempt was

Browser_Back::
send, {F2}
Sleep 300
;send, {Home}
FormatTime timestamp, A_Now, yyMMdd-
Send % timestamp
return

I started with send, {F2}+{Home} which did not work, thinking actions was too quick I added the delay
I know the last 3 lines work when used on their own, I would use F2 key and Home and add the current "Date -"

I am stuck something is wrong in my thinking. I need some pointers?
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to add a 'datestamp'

17 Apr 2019, 05:05

I just changed the hotkey and removed the semicolon preceding Send, {Home}. It's working here in explorer windows on Win 10.
starling22
Posts: 12
Joined: 26 Sep 2018, 05:43

Re: How to add a 'datestamp'

18 Apr 2019, 02:06

Took me some time to figure out how to get it going. Lack of experience one thing.

The "Browser_Back" can not be used in the script above, it will work fine with a script using only the last 3 lines, I had tested this and therefore it took me some time to find out that it will not work with the added lines using {F2} and {Home}, the semicolon needs to be removed. The semicolon used when I was trying to brake down the script operation.

So at the moment it works with using "^j::" until I find out more or another key to use on this multimedia keyboard.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, RussF, Spawnova and 131 guests