2 AUTOHOTKEY scripts Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

2 AUTOHOTKEY scripts

Post by dziobadam181 » 25 May 2022, 10:31

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 :)

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 25 May 2022, 10:36

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

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 25 May 2022, 11:07

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.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 25 May 2022, 11:17

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.

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 25 May 2022, 12:18

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.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 25 May 2022, 13:51

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%

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 26 May 2022, 02:04

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.

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 26 May 2022, 02:53

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 ?

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 26 May 2022, 04:29

Add file encoding.

Code: Select all

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

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 28 May 2022, 13:02

Still not working.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 28 May 2022, 13:52

Post your revised script. Delete the output file so that you can test again. Save your script as UTF-8 with BOM signature.

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 29 May 2022, 01:54

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.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 29 May 2022, 02:29

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%
Attachments
sepsa.txt
Input file
(7 Bytes) Downloaded 7 times

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 29 May 2022, 05:40

:( thanks for your advance,it is not working all i got is a blank note in notepad.

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 29 May 2022, 07:21

You can display contents of sepsa file within the script.

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 29 May 2022, 09:29

OK text,thank you :) If you wish please help me.
Attachments
sepsa_out.txt
(2 Bytes) Downloaded 6 times
sepsa.txt.txt
(11.66 KiB) Downloaded 7 times
skrypt.ahk
(391 Bytes) Downloaded 6 times

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 29 May 2022, 15:36

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.

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts

Post by dziobadam181 » 30 May 2022, 14:16

Sorry, I don't understand what is the difference between path and directory? I should copy H:\Mój dysk\artykuły

User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: 2 AUTOHOTKEY scripts

Post by mikeyww » 30 May 2022, 16:32

Try my script first. You can see the path to the file there. A directory is a folder.

dziobadam181
Posts: 15
Joined: 25 May 2022, 09:47

Re: 2 AUTOHOTKEY scripts  Topic is solved

Post by dziobadam181 » 31 May 2022, 02:53

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 !
Last edited by BoBo on 31 May 2022, 03:17, edited 2 times in total.
Reason: Added [code][/code]-tags. Please do this on your own within your following threads/postings. Thx.

Post Reply

Return to “Ask for Help (v1)”