Convert a normal text in file to a script of only one line with " `n "

Post your working scripts, libraries and tools
User avatar
Hajin
Posts: 32
Joined: 13 May 2016, 09:16

Convert a normal text in file to a script of only one line with " `n "

26 May 2016, 16:39

In my scripts, one time i had to use one thing different...
In this situation i had to make one script generate another script...
With his content different for each case; controlled for conditions, readings of .ini files, etc. ...
The script generated is actioned automatically, in this detail also controlled for conditions, readings of .ini files, etc. ...
A little example with conditions to explain:

Code: Select all

if a = 1
{
	text_test = ;script 1 here
}
else
{
	text_test = ;script 2 here
}

FileDelete, %A_ScriptDir%\Test.ahk
FileAppend, %text_test%, Test.ahk,
I arrived in a situation that I needed put a long script in only one line to be fast...
For this i had to use various `n for each line (the AHK's operation)...
I created one script to convert the model(written manually) of script to be automatically generated to the version in only one line.

The Script Of Conversion:

Code: Select all

/*

------------------------------------------------------------------------------------------------------------------------
USAGE
the lines quantity are placed in the "Lines" variable in this script
the mouse cursor is placed in the end of the last line, in the script to be converted
the default key to execute de script is: Ctrl + G

basic sequence used: enter, up, ``n, home, backspace, end
------------------------------------------------------------------------------------------------------------------------

*/

Lines = 19
Count = 0
time =

^g::
{
	msgbox, 257, conversion
	ifmsgbox ok
	{
		loop %Lines%
		{
		count += 1
			if lines = 1
			{
				Send {enter}
				Sleep, %time%
				Send {up}
				Sleep, %time%
				Send ``n
				Sleep, %time%
				Send {home}
				Sleep, %time%			
				Send {home}
				Sleep, %time%			
				count = 0
				Sleep, %time%			
				Break
			}
			else
			{
				if count = %lines%
				{
					Send {enter}
					Sleep, %time%
					Send {up}
					Sleep, %time%
	/*
					Send ``n
					Sleep, %time%
					Send {home}
					Sleep, %time%
					Send {home}
					Sleep, %time%
					Sleep, %time%
	*/
					count = 0
					Break
				}
				else
				{
					Send {enter}
					Sleep, %time%
					Send {up}
					Sleep, %time%
					Send ``n
					Sleep, %time%
					Send {home}
					Sleep, %time%
					Send {home}
					Sleep, %time%
					Send {backspace}
					Sleep, %time%
					Send {end}
					Sleep, %time%
				}
			}
		}
	}
	else
	{}
}
Maybe ``n have to be replaced for `n in the "ENG-Keyboard"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here some small examples to explain:

The Script that will generate the other script:

Code: Select all

;Looks like this must be used to the script automaticaly generated
var_symbol := "%"

text_test = ;the script must be placed here

FileDelete, %A_ScriptDir%\Test.ahk
FileAppend, %text_test%, Test.ahk,
The model(written manually) of the script to be automatically generated (the script of conversion must be used in this):

Code: Select all

msgbox, 257, Continue?
ifmsgbox ok
{
	msgbox, 257, Continue More?
	ifmsgbox ok
	{
		a = End
		msgbox, %var_symbol%a%var_symbol%
	}
	else
	{

	}
}
else
{

}
The script that will generate the other script (with the script converted)(in notepad the script converted have only one line):

Code: Select all

;Looks like this must be used to the script automaticaly generated
var_symbol := "%"

text_test = msgbox, 257, Continue?`nifmsgbox ok`n{	`nmsgbox, 257, Continue More?	`nifmsgbox ok	`n{		`na = End		`nmsgbox, %var_symbol%a%var_symbol%	`n`n}	`nelse	`n{	`n`n}`n}`nelse`n{`n`n}

FileDelete, %A_ScriptDir%\Test.ahk
FileAppend, %text_test%, Test.ahk,
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Why no make one script different for each situation, and simply use each of they for each situation?
Because one script autmatically generated can have his content modificed for each situation...
And in some cases of various situations, is better have one script to all situations and no one to each situation.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If anyone know other way can communicate here...
My script is good(so I put in this session) but the script automatically generated got this form while ready(without indents):

Code: Select all

msgbox, 257, Continue?
ifmsgbox ok
{
msgbox, 257, Continue More?
ifmsgbox ok
{
a = End
msgbox, %a%
}
else
{

}
}
else
{

}
In this form, in long scripts, only one machine understands :)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
____________________________________________________________________________________

Can anyone help me here?
https://autohotkey.com/boards/viewtopic ... 18&t=17798

My Scripts In This Forum:
____________________________________________________________________________________

Return to “Scripts and Functions”

Who is online

Users browsing this forum: aseiot and 55 guests