Welcome Guest.   Make a donation to an author on the site April 24, 2014, 05:35:05 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2010! Download 24 custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Create an empty txt file in the active window  (Read 4586 times)
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« on: June 16, 2012, 01:35:25 PM »

Create an empty txt file in the active window

I would like the code for create an empty txt file , by example instructions.txt in the folder open and active with a hotkey assign.


In other words create a file in the open window.

I supposed i need an ini configuration file for this purpose.

 Kiss
Logged
AbteriX
Charter Honorary Member
***
Posts: 1,021


Member #520

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #1 on: June 16, 2012, 03:08:56 PM »

Which window do you talk about?
WinExplorer? Try right click context menu > New > Text file
Logged

Greetings, Stefan.
c.gingerich
Supporting Member
**
Posts: 411



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: June 16, 2012, 03:15:22 PM »

Here is an AutoHotkey script that will do what you ask (attached is an compiled EXE as well). You can change the hotkey by editing the script. Right now it is set to Win+N (#n in the script). This works on my Windows 7 system. Not sure about others, you'll have to test it out. Hope this helps.

[copy or print]
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Chris Gingerich
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in

your Windows folder)
;

; Creates a new textfile in the current folder if an explorer window is active.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#n::
IfWinActive,ahk_class CabinetWClass
{
  Send !fwt
}

* HotText Snack.exe (610.26 KB - downloaded 68 times.)
Logged

MilesAhead
Member
**
Posts: 4,468



View Profile Give some DonationCredits to this forum member
« Reply #3 on: June 16, 2012, 03:27:32 PM »

If an item to create a new text file is not already in the New menu you can add it using this info:

http://windowsxp.mvps.org/shellnewadd.htm

Also you can put a file such as Template.txt in C:\Windows\ShellNew

and put that info in the registry key.  The file will copy whatever boiler plate text is in the template file.

Also you can create an ahk_group to add more window classes such as Progman and WorkerW to do the same thing with the desktop New menu.

The New menu does not open in Computer. You'll need some test to screen out situations where Computer is the "folder" currently open or where a file or folder is selected. If a folder or file is selected you don't get the New menu. You get the context menu for a folder or for that file type. (There's always a fly in said ointment.) smiley



Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

MilesAhead
Member
**
Posts: 4,468



View Profile Give some DonationCredits to this forum member
« Reply #4 on: June 16, 2012, 04:03:26 PM »

This is what I have in AutoIt3. It suffers from the same foible that you have to make sure nothing on the desktop or in the folder is selected. (Also as I mentioned, it doesn't work in Computer and other special Shell Object folders, which may include the libraries.)


[copy or print]
#include <WinAPI.au3>

$hotkey = "^+{F10}"
If Not HotKeySet($hotkey, "_MakeNewTextFile") Then
MsgBox(0x1010,"MakeNewTextFile",$hotkey & " could not be assigned as Hotkey")
Exit
EndIf

While 1
Sleep(100)
WEnd

Func _MakeNewTextFile()
Local $handle = _WinAPI_GetForegroundWindow()
Local $className = _WinAPI_GetClassName($handle)
If $className = "Progman" Or $className = "WorkerW" Or $className = "ExploreWClass" Or $className = "CabinetWClass" Then
Send("{AppsKey}")
Sleep(10)
Send("w")
Sleep(10)
Send("t")
Sleep(10)
Send("instructions")
EndIf
EndFunc
« Last Edit: June 16, 2012, 05:20:27 PM by MilesAhead » Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #5 on: June 16, 2012, 05:43:14 PM »

Wonderful indeed. I promised try and comment.
Now I have a piece of code from AHK and need something else. But that is another post.

Thanks everyone.
Miles I am enjoying every day ReOpen.
Best Regards
Logged
MilesAhead
Member
**
Posts: 4,468



View Profile Give some DonationCredits to this forum member
« Reply #6 on: June 16, 2012, 06:04:19 PM »

Miles I am enjoying every day ReOpen.
Best Regards


Thanks. Glad you like it. smiley
Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

MilesAhead
Member
**
Posts: 4,468



View Profile Give some DonationCredits to this forum member
« Reply #7 on: June 16, 2012, 06:32:59 PM »

Another approach that may work a bit more reliably uses clipboard in a folder. It uses the same Send key technique for desktop.  But inside a folder, select one folder with the mouse and hit the hotkey. It should only try to create instructions.txt if the highlighted item is a folder. Since that creates the file inside the folder, I use Run to launch it. Might save opening the selected folder and hunting for the file. Since it uses FileAppend function, if the file already exists in the folder, it should open it. You can spiff up the code a bit by doing stuff like saving clipboard contents and restoring etc... This is just a working skeleton.


[copy or print]
#SingleInstance force
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

GroupAdd,DeskGroup,ahk_class CabinetWClass
GroupAdd,DeskGroup,ahk_class ExploreWClass
GroupAdd,DeskGroup,ahk_class Progman
GroupAdd,DeskGroup,ahk_class WorkerW

#IfWinActive ahk_group DeskGroup
^+F10::
  WinGetClass,class,A
  if (class = "Progman") or (class = "WorkerW")
  {
    Send {AppsKey}wt
    Sleep,10
    Send instructions
  }
  else if (class = "CabinetWClass") Or (class = "ExploreWClass")
  {
    Clipboard=
    Send ^c
    ClipWait,2
    ff = %Clipboard%
    if (!InStr(FileExist(ff),"D"))
      SoundPlay, *16
    else
    {
      ff := ff "\instructions.txt"
      FileAppend,,%ff%
      Run,%ff%
    }
  }
  _EmptyWorkingSet()
return

_EmptyWorkingSet()
{
  return DllCall("psapi.dll\EmptyWorkingSet", "UInt", -1)
}


Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #8 on: June 17, 2012, 01:56:47 PM »

Here is an AutoHotkey script that will do what you ask (attached is an compiled EXE as well). You can change the hotkey by editing the script. Right now it is set to Win+N (#n in the script). This works on my Windows 7 system. Not sure about others, you'll have to test it out. Hope this helps.

[copy or print]
;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         Chris Gingerich
;
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in

your Windows folder)
;

; Creates a new textfile in the current folder if an explorer window is active.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

#n::
IfWinActive,ahk_class CabinetWClass
{
  Send !fwt
}

 Kiss undecided
I am trying to understand the hotkey. I have to study AHK of course.

I'll come back and comment.
 smiley
Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #9 on: June 17, 2012, 02:06:04 PM »

 Grin
Seen

Win+n

By the way. I am studying your web and seems you have a reward soft perhaps similar to Points Motivator from Mouser. I will take a good look. It's very interesting.

Best Regards

the script is residente. I am creating instructions.txt files only when I am downloading wonderful software to document the installation. it's not all time, so I would prefer one icon less in the tray icon.
I have hidden someones, but I have a lot and sometimes problems of memory

 tongue


Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #10 on: June 17, 2012, 02:08:54 PM »

 Kiss
It's difficult for me to understand this phrase :
"Template script (you can customize this template by editing "ShellNew\Template.ahk" in

your Windows folder)"

I'll try in the C:\Windows\ Folder and comment.

Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #11 on: June 17, 2012, 02:13:24 PM »

Not found in that folder. I'll try in the entire installation disk M: . if not found I'll try in the portable installation directory of AHK. If not found I will look in the windows registry.
 smiley
Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #12 on: June 17, 2012, 02:14:21 PM »

Found in

M:\Windows\Shellnew
 Kiss
Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #13 on: June 17, 2012, 02:17:13 PM »

This file template.ahk I don't understand what I have to do :

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

 Kiss
Logged
MilesAhead
Member
**
Posts: 4,468



View Profile Give some DonationCredits to this forum member
« Reply #14 on: June 17, 2012, 02:18:18 PM »

Kiss
It's difficult for me to understand this phrase :
"Template script (you can customize this template by editing "ShellNew\Template.ahk" in

your Windows folder)"

I'll try in the C:\Windows\ Folder and comment.



You have to create the folder in ShellNew if you want it's contents copied to files created under New. For example if you right click in a folder and select New AutoHotKey file, and get not and empty file but stuff like
#NoEnv
Sendmode,Input

that comes from C:\Windows\ShellNew\Template.ahk

The ahk install puts it there.
You don't need the file unless you want boiler plate text in every file created.

In my Templay.ahk file I have a whole skeleton program with hotkey, about dialog, donate command in tray menu etc...  Then I make changes.. if it's for a basic hotkey tray app.
Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

MilesAhead
Member
**
Posts: 4,468



View Profile Give some DonationCredits to this forum member
« Reply #15 on: June 17, 2012, 02:20:35 PM »

This already explains it better than I can in a few paragraphs:

http://windowsxp.mvps.org/shellnewadd.htm

If you just want an empty text file, you don't have to bother with the template.
Logged

"I don’t want to belong to any club that would have me as a member."
 - Groucho Marx

Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #16 on: June 17, 2012, 02:21:13 PM »

I am lost. I'll wait your advice.
if with the same folder from the program I key Win+n this is the result :



I will revised because my windows is spanish version. So perhaps the hotkey don't go well in my system. i will comment. Excuse me.
 Grin
Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #17 on: June 17, 2012, 02:22:26 PM »

This already explains it better than I can in a few paragraphs:

http://windowsxp.mvps.org/shellnewadd.htm

If you just want an empty text file, you don't have to bother with the template.


Thanks Miles. i haven't reach your script yet
 tongue
Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #18 on: June 17, 2012, 03:08:00 PM »

This is what I have in AutoIt3. It suffers from the same foible that you have to make sure nothing on the desktop or in the folder is selected. (Also as I mentioned, it doesn't work in Computer and other special Shell Object folders, which may include the libraries.)


[copy or print]
#include <WinAPI.au3>

$hotkey = "^+{F10}"
If Not HotKeySet($hotkey, "_MakeNewTextFile") Then
MsgBox(0x1010,"MakeNewTextFile",$hotkey & " could not be assigned as Hotkey")
Exit
EndIf

While 1
Sleep(100)
WEnd

Func _MakeNewTextFile()
Local $handle = _WinAPI_GetForegroundWindow()
Local $className = _WinAPI_GetClassName($handle)
If $className = "Progman" Or $className = "WorkerW" Or $className = "ExploreWClass" Or $className = "CabinetWClass" Then
Send("{AppsKey}")
Sleep(10)
Send("w")
Sleep(10)
Send("t")
Sleep(10)
Send("instructions")
EndIf
EndFunc

I'll try in autoit and comment
Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #19 on: June 17, 2012, 04:16:22 PM »

NO.
I am thinking and thinking.
Now I need more.
I would like a hotkey not resident program to start a script able to present a list selection from the cursor with the alternatives names to the txt to create.
Always to do in the active window if exist. If not the script don't start.

 Kiss

so. It's a second contextual menu activated with the hotkey. A selection list. Once the selection is done the txt with the name of the selection is created.

Is it possible ?

 tongue
« Last Edit: June 17, 2012, 04:23:10 PM by Contro » Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #20 on: June 18, 2012, 01:43:10 PM »

Now I understand why in the script you propose the hotkey too.
I have a program to control the hotkeys that is resident. So I only need the code

1. Open a selection list
2. With the selected item create a txt file in the active window .

 Kiss
Logged
Contro
Participant
*
Posts: 1,943

View Profile Give some DonationCredits to this forum member
« Reply #21 on: June 18, 2012, 08:24:14 PM »

I have received help from dylan904

[copy or print]
#SingleInstance Force

#if winactive("ahk_class CabinetWClass")
{
  ^!z::
  WinGet, WinID, ID, A
  ControlGetText, DesPath, Edit1, ahk_id %WinID%
  Gui, Add, ListView, r10 NoSort gChoose vChosenName, File Name
  For A,B in {1:"File1.txt",2:"File2.txt",3:"File3.txt",4:"File4.txt",5:"File5.txt",6:"File6.txt",7:"File7.txt",8:"File8.txt",9:"File9.txt",10:"File10.txt"}
    LV_Add("",B)
  Gui, Show,, Choose File Name
  Return
 
  Choose:
  LV_GetText(ChosenName, A_EventInfo)
  Gui, Destroy
  FileAppend,, %DesPath%\%ChosenName%
  Sleep, 850
  While (ClipBoard != DesPath "\" ChosenName)
  {
    Send, % SubStr(ChosenName, 1, 1)
    Sleep, 15
    SendInput, ^c
    Sleep, 15
  }
  Return
}

Goes well. Rarely fails, but his author tells :
"To the extent of my knowledge, Windows Explorer is not very easy to manipulate.
But you may use something like this, you can use an .ini instead, but for now i just used a general list of file names to choose from (Control+Alt+z to activate)..."

 Kiss

Now I am considering the possibility of insert date/time in the name of the txt file.
I supposed I have to use a system memory variable and propose in the name of the txt file.
For me is enough to edit the ahk file.

 tongue
Logged
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.042s | Server load: 0.1 ]