activation with altGr+n
By default text files are created, but it can easily be changed for .ahk for instance ^^
Notice:
The text file is created in the active window, but if the active window is not a Windows window, the file is created on the desktop
Only tested on Vista
And maybe my english translation could be better, if you have any suggestions, tell me;)
http://yfrog.com/02newtxtj
In English:
#SingleInstance Force
#Persistent
#NoEnv
SendMode Input
SetBatchLines -1
DetectHiddenText On
#NoTrayIcon
<^>!n::
default=
default2=TXT
{ ;searching for "path"
WinGetClass Class, A
If Class = Progman
{
Path = %A_Desktop%
}
else if Class <> CabinetWClass
{
Path = %A_Desktop%
}
else
{
ControlGetText Path, Edit1, ahk_class %Class%
}
}
NewTry2:
{ ;creation du GUI
Gui, Add, Edit, vTxtName x5 y26 w162 h22 , %default% ; edit du nom du fichier
Gui, Add, Edit, vExtName x181 y26 w49 h22 , %default2%
Gui, Add, Button, Default x34 y55 w54 h24 , OK
Gui, Add, Button, x146 y55 w54 h24 , Cancel
Gui, Add, Text, x5 y5 w224 h16 , Set the file name:
Gui, Add, Text, x173 y30 w11 h22 , .
Gui, Show, x416 y367 h87 w243, New text file
Return
}
ButtonOK:
Gui, Submit
Gui, Destroy
Test:
;verification de la validité du nom donné ( /\:?*"<>| sont interdits )
{
if TxtName=
{
MsgBox,, New text file, You didn't set any file name !
default2 = %ExtName%
Goto NewTry2
}
else if ExtName=
{
MsgBox,, New text file, you didn't set any extension !
default = %TxtName%
default2=
{ ;creation du GUI specifique "pas d'extension" + goto Test
Gui, Add, Edit, vExtName x181 y26 w49 h22 , %default2%
Gui, Add, Edit, vTxtName x5 y26 w162 h22 , %default% ; edit du nom du fichier
Gui, Add, Button, Default x34 y55 w54 h24 , OK
Gui, Add, Button, x146 y55 w54 h24 , Cancel
Gui, Add, Text, x5 y5 w224 h16 , Set the file name:
Gui, Add, Text, x173 y30 w11 h22 , .
Gui, Show, x416 y367 h87 w243, New text file
Return
OK:
Gui, Submit
Gui, Destroy
}
Goto Test
}
else if ( InStr(TxtName,"/") || InStr(TxtName,"\") || InStr(TxtName,":") || InStr(TxtName,"?") || InStr(TxtName,"*") InStr(TxtName,"<") || InStr(TxtName,">") || InStr(TxtName,"|") )
{
MsgBox,, New text file, Invalid folder name.`n`nAre forbidden: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
else ifinstring TxtName, "
{
MsgBox,, New text file, Invalid folder name.`n`nAre forbidden: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
else if ( InStr(ExtName,"/") || InStr(ExtName,"\") || InStr(ExtName,":") || InStr(ExtName,"?") || InStr(ExtName,"*") InStr(ExtName,"<") || InStr(ExtName,">") || InStr(ExtName,"|") )
{
MsgBox,, New text file, Invalid folder name.`n`nAre forbidden: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
else ifinstring ExtName, "
{
MsgBox,, New text file, Invalid folder name.`n`nAre forbidden: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
IfExist %Path%\%TxtName%.%ExtName%
{
MsgBox,, New text file, This file name already exists.
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
return
}
}
StringLower, ExtName, ExtName
FileAppend,, %Path%\%TxtName%.%ExtName%
if ExtName=txt
{
run %Path%\%TxtName%.%ExtName%
}
return
ButtonCancel:
GuiClose:
Gui,Destroy
ExitApp
but also in French
#SingleInstance Force
#Persistent
#NoEnv
SendMode Input
SetBatchLines -1
DetectHiddenText On
#NoTrayIcon
<^>!n::
default=
default2=TXT
{ ;recherche de path
WinGetClass Class, A
If Class = Progman
{
Path = %A_Desktop%
}
else if Class <> CabinetWClass
{
Path = %A_Desktop%
}
else
{
ControlGetText Path, Edit1, ahk_class %Class%
}
}
NewTry2:
{ ;creation du GUI
Gui, Add, Edit, vTxtName x5 y26 w162 h22 , %default% ; edit du nom du fichier
Gui, Add, Edit, vExtName x181 y26 w49 h22 , %default2%
Gui, Add, Button, Default x34 y55 w54 h24 , OK
Gui, Add, Button, x146 y55 w54 h24 , Annuler
Gui, Add, Text, x5 y5 w224 h16 , Entrez le nom du fichier texte:
Gui, Add, Text, x173 y30 w11 h22 , .
Gui, Show, x416 y367 h87 w243, Nouveau fichier texte
Return
}
ButtonOK:
Gui, Submit
Gui, Destroy
Test:
;verification de la validité du nom donné ( /\:?*"<>| sont interdits )
{
if TxtName=
{
MsgBox,, Nouveau fichier texte, Vous n'avez pas entré de nom de fichier !
default2 = %ExtName%
Goto NewTry2
}
else if ExtName=
{
MsgBox,, Nouveau fichier texte, Vous n'avez pas entré d'extension !
default = %TxtName%
default2=
{ ;creation du GUI specifique "pas d'extension" + goto Test
Gui, Add, Edit, vExtName x181 y26 w49 h22 , %default2%
Gui, Add, Edit, vTxtName x5 y26 w162 h22 , %default% ; edit du nom du fichier
Gui, Add, Button, Default x34 y55 w54 h24 , OK
Gui, Add, Button, x146 y55 w54 h24 , Annuler
Gui, Add, Text, x5 y5 w224 h16 , Entrez le nom du fichier texte:
Gui, Add, Text, x173 y30 w11 h22 , .
Gui, Show, x416 y367 h87 w243, Nouveau fichier texte
Return
OK:
Gui, Submit
Gui, Destroy
}
Goto Test
}
else if ( InStr(TxtName,"/") || InStr(TxtName,"\") || InStr(TxtName,":") || InStr(TxtName,"?") || InStr(TxtName,"*") InStr(TxtName,"<") || InStr(TxtName,">") || InStr(TxtName,"|") )
{
MsgBox,, Nouveau fichier texte, Ce nom de fichier est invalide.`n`nSymboles interdits: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
else ifinstring TxtName, "
{
MsgBox,, Nouveau fichier texte, Ce nom de fichier est invalide.`n`nSymboles interdits: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
else if ( InStr(ExtName,"/") || InStr(ExtName,"\") || InStr(ExtName,":") || InStr(ExtName,"?") || InStr(ExtName,"*") InStr(ExtName,"<") || InStr(ExtName,">") || InStr(ExtName,"|") )
{
MsgBox,, Nouveau fichier texte, Ce nom de fichier est invalide.`n`nSymboles interdits: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
else ifinstring ExtName, "
{
MsgBox,, Nouveau fichier texte, Ce nom de fichier est invalide.`n`nSymboles interdits: / \ : ? * " < > |
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
}
IfExist %Path%\%TxtName%.%ExtName%
{
MsgBox,, Nouveau fichier texte, Ce nom de fichier existe déjà.
default = %TxtName%
default2 = %ExtName%
Goto NewTry2
return
}
}
StringLower, ExtName, ExtName
FileAppend,, %Path%\%TxtName%.%ExtName%
if ExtName=txt
{
run %Path%\%TxtName%.%ExtName%
}
return
ButtonAnnuler:
GuiClose:
Gui,Destroy
ExitApp
edit: corrected the cancel button problem; it was due to translation ^^
but i won't have xp before 2weeks, sorry




