It's 1am and I can't figure out what's wrong.
Hoping someone can point out the flaw.
Code is started by pressing Ctrl + Window + F9.
I get random crazy results. If running from new, it only stores 2 URLs in the file and stops. If I run again, then it store 5 URL's more.
Here's the code:
Code: Select all
#NoEnv ; Recommended setting for new AHK scripts. Makes sure AHK doesn't access empty variables.
#SingleInstance force
;===============================
/*
The code is meant to cycle through open tabs and store URLs in a text file.
The code stops when we come to a URL that we already have stored.
If 2 URLs are open in tabs and are the same URL, then the code won't work. But I can live this!
*/
;===============================
MsgBox, ,, AutoHotKey ##%A_ScriptName%## now loaded and ready to be used, 1.5
; Start coding in the line below.
^#F9::
saving_tabs_array := []
Loop, 40 ;Intentionally I put a fixed number here - to stop looping forever if I get my loop wrong
{
temp_array_string := ""
for each, array_element in saving_tabs_array
temp_array_string .= A_Index . ": " . array_element . "`n"
if (InStr(temp_array_string, Clipboard)) ; Checking to see if we have cycled back to the same URL
{
;MsgBox, URLs: %temp_array_string%
break
}
else
{
; Value does not exist in the array of URLs, so we add to the array
saving_tabs_array.Push(Clipboard)
SendInput ^{tab} ; Move to next tab
SendInput !d ; This sends alt + d
SendInput ^c ; send ctrl C - we have the current URL on clipboard now
Sleep 100 ; we sleep for 100 miliseconds - AHK doesn't work properly without sleeps.
}
}
FileAppend, %temp_array_string%, tabs.txt
Return
^#F10::Reload ;<- Windows Key + F10 causes the script to reload itself
^#F11::
MsgBox, ,, AutoHotKey ##%A_ScriptName%## Code about to close, 2.5
ExitApp ;<- Exit the app
Return
QUESTION: how do I clear the contents of the text file and write over whatever is there previously?
Thanks