Page 1 of 2

2 AUTOHOTKEY scripts

Posted: 25 May 2022, 10:31
by dziobadam181
Hi,
Im now at programming,im medical doctor by proffesion :) is't my hobby.
I want to be more productive,i want to change press tab to win + 1,win + 2 win + 3 to swith active windows.
The second script it to finde and replece multiple all phrases forexemple "OUN " Ośrodkowy układ nerwowy"
Both script should be cut off after pressing esc.
I'm working currently on windows 10.
Thanks for your help :)

Re: 2 AUTOHOTKEY scripts

Posted: 25 May 2022, 10:36
by mikeyww
Welcome to this AutoHotkey forum!

The AHK documentation is a good starting point for explanations & examples, along with this forum. Best of luck.

Code: Select all

Tab::Send !{Tab}
::oun::Ośrodkowy układ nerwowy
More: Alt-Tab hotkeysHotstrings

Re: 2 AUTOHOTKEY scripts

Posted: 25 May 2022, 11:07
by dziobadam181
Sorry,it is not working,a want to achive affect a windows key press 1 for a 1 window then windows key press 2 and so on with you script a see only a mess on my screen.

Code: Select all

tab::send #{1}
is running but a dont't know how to add varible to this and achive affect tab::send #{2}
For a second script you don't understand i got a text in a text file a want a program with find and replace mulityple variables.

Re: 2 AUTOHOTKEY scripts

Posted: 25 May 2022, 11:17
by mikeyww

Code: Select all

Tab::Send % "#" ++n := Mod(0 n, 3)
To read a file, use FileRead. To replace a string, use StrReplace. To save your file, use FileAppend. Each page has examples at the bottom.

Re: 2 AUTOHOTKEY scripts

Posted: 25 May 2022, 12:18
by dziobadam181

Code: Select all

FileRead, Contents, H:\Mój dysk\artykuły\kleszcze.txt
Loop
{
MyString := StrReplace(kleszcze, "OUN", "ośrodkowy układ nerwowy", Count)
    if (Count = 0)  ; No more replacements needed.
        break
}

FileAppend,"OUN",H:\Mój dysk\artykuły\kleszcze1.txt
This is what a got but it is not working ,it create a file kleszcze1 but only with OUN.

Re: 2 AUTOHOTKEY scripts

Posted: 25 May 2022, 13:51
by mikeyww

Code: Select all

infile  = H:\Mój dysk\artykuły\kleszcze.txt
outfile = %A_ScriptDir%\kleszcze-out.txt
FileRead, text, %infile%
out := StrReplace(text, "oun", "ośrodkowy układ nerwowy")
FileAppend, %out%, %outfile%
Run, %outfile%

Re: 2 AUTOHOTKEY scripts

Posted: 26 May 2022, 02:04
by dziobadam181
Thanks for you help,it is almost done but it can't insert polish chart "ś" and "ł" in output file "ox9crodkowy ukx53ad ". it should be "ośrodkowy układ"
How can i apply pollish chart into that string ? In a input file everthing is working corrtectly.

Re: 2 AUTOHOTKEY scripts

Posted: 26 May 2022, 02:53
by dziobadam181

Code: Select all

the_language :=languageCode_0415 := "Polish"_%A_Language%  ; Get the name of the system's default language.
infile  = H:\Mój dysk\artykuły\kleszcze.txt
outfile = %A_ScriptDir%\kleszcze-out.txt
FileRead, text, %infile%
out := StrReplace(text, "oun", "ośrodkowy układ nerwowy")
FileAppend, %out%, %outfile%
Run, %outfile%
What is wrong with this code ?

Re: 2 AUTOHOTKEY scripts

Posted: 26 May 2022, 04:29
by mikeyww
Add file encoding.

Code: Select all

FileAppend, %out%, %outfile%, UTF-16

Re: 2 AUTOHOTKEY scripts

Posted: 28 May 2022, 13:02
by dziobadam181
Still not working.

Re: 2 AUTOHOTKEY scripts

Posted: 28 May 2022, 13:52
by mikeyww
Post your revised script. Delete the output file so that you can test again. Save your script as UTF-8 with BOM signature.

Re: 2 AUTOHOTKEY scripts

Posted: 29 May 2022, 01:54
by dziobadam181

Code: Select all

the_language :=languageCode_0415 
infile  = H:\Mój dysk\artykuły\sepsa.txt
outfile = %A_ScriptDir%\sepsa_out.txt
FileRead, text, %infile%
out := StrReplace(text, "OCŻ", "ośrodkowe ciśnienie żylne")
FileAppend, %out%, %outfile%,UTF-16
Run, %outfile%
I changed a file.It is empty now.

Re: 2 AUTOHOTKEY scripts

Posted: 29 May 2022, 02:29
by mikeyww
The following worked here. Input file & script are UTF-8 with BOM signature.

Code: Select all

infile  = H:\Mój dysk\artykuły\sepsa.txt
; infile  = %A_ScriptDir%\sepsa.txt
outfile = %A_ScriptDir%\sepsa_out.txt
If !FileExist(infile) {
 MsgBox, 48, Error, File not found. Aborting.`n`n%infile%
 Return
}
FileRead, text, %infile%
out := StrReplace(text, "OCŻ", "ośrodkowe ciśnienie żylne")
FileRecycle, %outfile%
FileAppend, %out%, %outfile%, UTF-16
Run, %outfile%

Re: 2 AUTOHOTKEY scripts

Posted: 29 May 2022, 05:40
by dziobadam181
:( thanks for your advance,it is not working all i got is a blank note in notepad.

Re: 2 AUTOHOTKEY scripts

Posted: 29 May 2022, 07:21
by mikeyww
You can display contents of sepsa file within the script.

Re: 2 AUTOHOTKEY scripts

Posted: 29 May 2022, 09:29
by dziobadam181
OK text,thank you :) If you wish please help me.

Re: 2 AUTOHOTKEY scripts

Posted: 29 May 2022, 15:36
by mikeyww
The infile is not a directory. It is the full path to your source text file. Before you change the script, test the one that I posted.

Re: 2 AUTOHOTKEY scripts

Posted: 30 May 2022, 14:16
by dziobadam181
Sorry, I don't understand what is the difference between path and directory? I should copy H:\Mój dysk\artykuły

Re: 2 AUTOHOTKEY scripts

Posted: 30 May 2022, 16:32
by mikeyww
Try my script first. You can see the path to the file there. A directory is a folder.

Re: 2 AUTOHOTKEY scripts  Topic is solved

Posted: 31 May 2022, 02:53
by dziobadam181

Code: Select all

the_language :=languageCode_0415 
infile = D:\skrypty autohotkey\sepsa
outfile = %A_ScriptDir%\sepsa_out.txt
FileRead, text, %infile%
out := StrReplace(text, "OCŻ", "ośrodkowe ciśnienie żylne")
FileAppend, %out%, %outfile%,UTF-16
Run, %outfile%

outfile = %A_ScriptDir%\sepsa_out.txt
If !FileExist(infile) {
 MsgBox, 48, Error, File not found. Aborting.`n`n%infile%
 Return
}
Now is working thank you !