topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Monday March 18, 2024, 10:04 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Create an empty txt file in the active window  (Read 18058 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Create an empty txt file in the active window
« on: June 16, 2012, 01:35 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.

 :-*

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #1 on: June 16, 2012, 03:08 PM »
Which window do you talk about?
WinExplorer? Try right click context menu > New > Text file

c.gingerich

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 748
    • View Profile
    • The Blind House
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #2 on: June 16, 2012, 03:15 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.

;
; 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
}

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #3 on: June 16, 2012, 03:27 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.mvp....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.) :)




MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #4 on: June 16, 2012, 04:03 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.)


#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 PM by MilesAhead »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #5 on: June 16, 2012, 05:43 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

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #6 on: June 16, 2012, 06:04 PM »
Miles I am enjoying every day ReOpen.
Best Regards


Thanks. Glad you like it. :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #7 on: June 16, 2012, 06:32 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.


#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)
}



Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #8 on: June 17, 2012, 01:56 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.

;
; 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
}

 :-* :-\
I am trying to understand the hotkey. I have to study AHK of course.

I'll come back and comment.
 :)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #9 on: June 17, 2012, 02:06 PM »
 ;D
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

 :P



Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #10 on: June 17, 2012, 02:08 PM »
 :-*
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.


Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #11 on: June 17, 2012, 02:13 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.
 :)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #12 on: June 17, 2012, 02:14 PM »
Found in

M:\Windows\Shellnew
 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #13 on: June 17, 2012, 02:17 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.

 :-*

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #14 on: June 17, 2012, 02:18 PM »
:-*
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.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #15 on: June 17, 2012, 02:20 PM »
This already explains it better than I can in a few paragraphs:

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

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

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #16 on: June 17, 2012, 02:21 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 :

http://img341.imageshack.us/img341/9527/mozart17062012211815.png
Create an empty txt file in the active window


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.
 ;D

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #17 on: June 17, 2012, 02:22 PM »
This already explains it better than I can in a few paragraphs:

http://windowsxp.mvp....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
 :P

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #18 on: June 17, 2012, 03:08 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.)


#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

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #19 on: June 17, 2012, 04:16 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.

 :-*

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 ?

 :P
« Last Edit: June 17, 2012, 04:23 PM by Contro »

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #20 on: June 18, 2012, 01:43 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 .

 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Create an empty txt file in the active window
« Reply #21 on: June 18, 2012, 08:24 PM »
I have received help from dylan904

#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)..."

 :-*

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.

 :P