Notepad - how to open and save IN SPECIFIC folder

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jc5555
Posts: 6
Joined: 10 Apr 2021, 06:16

Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 09:12

Hello

I need help with a script to an action with .txt file - I didn`t see any advice like this - if it exist - I am really very sorry not to notice.

Every day I have to do one action in Total Commander - I need to open new folder, make an .txt file in this empty folder (mouse right-click, menu/new/.txt); open the file, copy some text inside and save it in this folder by Alt+F4 for example). There is no problem for me to do more of those actions - but I have a problem with making a new .txt file IN THIS FOLDER (NOT to open a notepad and saving it - choosing folder).

I thought it would be possible by making a script: I push Ctrl+Z and the script do: right-clik-mouse from the keybord, PageUp, PageUp, right-click and the same way clicking "new" position, ".txt". That I think I could write myself.

But there is a problem - my keybord DOESN`t have a RightMouse Key. There is possibility to make right click by FN + Right Control and it opens right-button-mouse menu, but - I don`t know why - in this menu there is NO "new" position. When I use real mouse - the position "new" is under the "make shortcut".

So I wanted to use "mouse" script - starting like this:

Code: Select all

#IfWinActive ahk_class TTOTAL_CMD
^z::  
Send {RButton down}
Sleep 500
this above actually opens right-clik-mouse menu WITH "new" position, but the window is not active, and I cannot make any keybord move like PgUp... I tried with WinActive or Activate - but still nothig - so I make something wrong for sure.

How it should be done properly, pliz? :-)

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

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 09:30

It's easy in TC. You can customize the TC start menu by adding a command that runs an AHK script, passing the active path on the AHK command line. Your script then copies a pre-existing null TXT file from some directory into your chosen directory. You can customize the TC start-menu command to use a keyboard shortcut.
Jc5555
Posts: 6
Joined: 10 Apr 2021, 06:16

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 10:30

Mike
I know that it is probably simple for someone who knows :-) But I am completely "green" - so I don`t know how to do - even what you say
Jc5555
Posts: 6
Joined: 10 Apr 2021, 06:16

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 10:36

To add - I know how to customize TC menu and add shorcuts - but still I don`t know how to write the script needed for "moving" .txt file from some directory to existing folder :-(
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 11:09

Step #1

In your Start Menu, add an item with:

Command: pathTo...\AutoHotkey.exe

Parameters: pathTo....\text.ahk %P

Step #2

text.ahk:

Code: Select all

FileAppend, New text here, % A_Args.1 ".txt"
Jc5555
Posts: 6
Joined: 10 Apr 2021, 06:16

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 13:24

Mike, thank you

I feel really like stupid, but I don`t know how to make it work.

I opened Edit Start Menu (in Total Commander I hope), then I added a position "txt", pasted text: pathTo...\AutoHotkey.exe in command line, and: pathTo....\text.ahk %P in parameters line, made begin line with: C:\Users\reporter\Desktop where is my txt.ahk and put the shorcut CTRL+ALT+F1 (there are only so "complicated shortcuts tu use) - I have communicate: "File doesn`t exist".

I really have no idea how to do it.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 14:38

Here is a TC screenshot after adding an item called "Test".

image210410-1528-001.png
image210410-1528-001.png (65.83 KiB) Viewed 1347 times

You change the two paths to match your system. You then use the exact AHK script that I provided (I called it test.ahk in my new example).

What happens: when you select the Start menu item in TC, it runs the AHK script, with the current path on the command line. The FileAppend line then appends the text as shown, to a file called ".txt" in that directory. If there is no such file, it will be created.

Test in a directory without restricted permissions, so that the FileAppend does not lead to an access error.

From your description, it appears that you specified a file called text.ahk, while your actual file had a different name: txt.ahk.
Eureka
Posts: 65
Joined: 03 Apr 2018, 13:31

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 15:19

A different approach:
  • In Total Commander, browse to the right folder
  • Press SHIFT+F4 to create a new text document
  • Choose New text document
  • Specify a name (somefile.txt for example)
  • Press ENTER or F4 on somefile.txt to open it in the default text editor
  • Paste your text
  • Save
  • Done

If the filename is always the same, you can automate this even further (click on a button and done).


BTW: SHIFT+F10 should work too if you have no Apps key.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 15:29

Yes, that works as well.

Code: Select all

#IfWinActive ahk_exe TOTALCMD64.EXE
F2::
Send +{F4}
WinWaitActive, Total Commander ahk_class TCOMBOINPUT ahk_exe TOTALCMD64.EXE,, 10
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the window. Aborting.
 Return
} Else Send {Text}.txt
Send {Enter}
Return
#IfWinActive
Eureka
Posts: 65
Joined: 03 Apr 2018, 13:31

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 16:30

And another, another approach:
  • Create a PasteText.ahk somewhere (in this example: X:\somewhere\PasteText.ahk). Content:

    Code: Select all

    FileAppend, %Clipboard%, some filename.txt, UTF-8
    (replace some filename.txt with the actual filename you want to create).
  • Create a new start menu entry (give it a recognizable name. In this example: Paste text in new file):
    • Command = "C:\Path To\AutoHotkeyU64.exe"
    • Parameters = "X:\somewhere\PasteText.ahk"
  • Save

Now you can:
- Copy the text to the clipboard
- go to your folder in TC
- Menu: Start > Paste text in new file
- Done.
Jc5555
Posts: 6
Joined: 10 Apr 2021, 06:16

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 20:36

Gentleman

Now I understand everything :-) You are really very patient...

If I may ask for one more thing... In all ways, using your advices from both of You - the .txt file appears in the chosen folder BUT - only if I make any additional action. For example I had to leave the folder and go into it again or copy another file to the folder - only after taking that kind of action - the new text file appears. It is like the folder doesn`t refresh by itself. Is it normal or there is something wrong with my system?

I also tried to move the command f.ex. "PasteText" from TC Menu Start to the main button bar - is it possible?

And really the last question - is there a possibility to make a convenient shortcut to use the functionality - not goint to the menu and clicking the command? I deliberately use "convenient" expression becouse TC gives possibility of a little bit unconvenient shortcuts like CTRL+ALT+F1 or even more sophisticated CTRL+ALT+SHIFT+F1...
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Notepad - how to open and save IN SPECIFIC folder

10 Apr 2021, 21:11

You are mostly asking questions about how Total Commander works.

Refresh: in TC, see Configuration -> Options -> Operation -> Refresh

Yes, you can define a button with a user-defined command.

https://www.ghisler.ch/wiki/index.php/User-defined_command

When you set up a Start Menu shortcut, you could use AHK to change the trigger, so that your AHK hotkey triggers the TC hotkey.
Jc5555
Posts: 6
Joined: 10 Apr 2021, 06:16

Re: Notepad - how to open and save IN SPECIFIC folder

11 Apr 2021, 06:32

I am sorry Mike
I asked about that just at the end - mainly because I cannot see .txt file created by the script. And I don`t know if it is becouse of TC or my system. If I just had to refresh folder every time - of course I can do it and make a refresh shortcut - which as far as I remember is under F2.
That is the question I couldn`t find answer for at TC community. Like - I didn`t find anwers for two other question asked - about reconfiguration menu button bar - altough I tried until morning time. But I see you are fluent TC user :-)

Thank you

PS.

I also want to give another way found meanwhile during my seek for solution of my problem:

In TC Configutration / Opitons / Misc. / Redefine keys I choose for example shortcut (hotkey) CTRL + Q.
I go to usercm.ini position at Category, click New (you may give a name of the action: "Opening txt")
In Command you put this text: cmd.exe /c"echo a > plik.txt" && notepad.exe plik.txt
Ok/Ok/Ok

When you go to the folder, push CTRL+Q - and new .TXT file creates in the folder, OPENS and waits for your action. Saving the file by f.e. ALT+F4 closes the file and save it IN THE folder :-)

Thank you for your help and I hope that someone find solution to similar problem - and most important - not just only one solution.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Notepad - how to open and save IN SPECIFIC folder

11 Apr 2021, 07:23

Nice solution! Thank you for sharing it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 192 guests