New .bat file button

Hello,

Can someone tell me how I can create a button\menu context that when clicked created a new bat file with a window prompting me to enter a name for it?

Cheers

The command you want is:

FileType NEW=.bat

Hi Nudel. Unfortunalty this doesn't work for me, if I change it to .txt it creates a text file ok but .bat does nothing. I wonder if it's because of this

Make sure you set your button function to "MS-DOS Batch function" then use this for your button commands.

type nul>"{dlgstring|Create new batch file here|My New Batch File}.bat"
pause

Once you're satisfied it works as you want, you can remove the pause command in the last line.

No.

You need this command:

Filetype NEW=.txt NEWNAME=temp.bat

This creates a new empty file named "temp.bat" ready for you to edit it's name in inline mode.

A different solution:

FileType NEW=.txt NEWNAME=norename:{dlgstring|Enter filename|temp.bat}

Instead of inline rename, this option opens a dialog for you to enter a name into rather than inline mode.

I was looking for an opus raw command to do this but this works great, apart from the flashing dos window but i'm being picky now.

Thanks a lot John and Nudel.

P.S. thanks for your answer as well Tanis, now I have a choice :slight_smile:

I just gave you one :stuck_out_tongue:

I like the two answers Tanis gave the most but, as a general bit of information, you can prevent a MS-DOS type buttons from opening DOS windows by setting the Run dropdown to Hide or, if it's a multi-line command, adding runmode hide as the first line of the command.

Nudel where is the run dropdown that you mention that I should set to hide?

One final question. Can I alter the "new" context menu that appears when you right click over an empty area of a lister and go down to the "new" submenu? I would like to add this new opus command into that sub menu and also remove some other stuff.

You don't need to set it for the comands Tanis gave (in fact, you can't as it'll be ghosted for internal commands) but it's at the bottom of the Command Editor dialog, if it's in single-line mode (i.e. not Advanced mode).

To edit it in both Explorer and Opus, use Microsoft TweakUI ("Templates" page).

I find it useful to ignore the New menu (although I've left it there) and add the few filetypes I want to create directly to the lister's right-click menu. This is not only more tidy but it's faster since you don't have to wait for the New menu to be built dynamically when you open it. If you want to do this in Opus, go to Customize, Context Menus and edit the Lister Context menu.

If you have a multi-line command, or you are in Advanced Edit mode, this field does not appear. Which is why Nudel told you to just type the following as your first command line:

Runmode Hide

You cannot make this change in Opus, the Templates (New) submenu is provided by the Windows operating system. Also that menu is also listed inside of Windows explorer, so putting an Opus command there is not something you want to do as it will error in your Windows Explorer (including on your Desktop).

Adding a template to the Windows-provided New menu is possible, though it is not for the faint at heart. Editing the registry is involved. I will show you how to do one for .cmd files (which is what you should use in Windows 2000/XP). Create a file Template.cmd. Here's mine below, it has some neat things people might like:

 @Echo Off
 Setlocal enableextensions
 CLS
 Echo.

:SetVars
Set Beep=a
Set Bullet=ú

:Logic
:: Place your command batch script logic between :Logic and :End

 Call :Tips
 Goto :EOF

:End
Endlocal
Goto :EOF

:: Only place called functions below this comment. Do NOT place an Exit
:: command anywhere in this script, if you plan to call it from other
:: batch scripts, doing so will exit the parent script as well!

:Tips
:: Text Border Codes
::
:: Copy and paste the special characters below to add borders around your
:: onscreen messages.
::
:: Single-line borders Double-line borders
:: ---------------------------- ----------------------------
:: Top Left Corner Ú Top Left Corner É
:: Horizontal Ä Horizontal Í
:: Top Right Corner ¿ Top Right Corner »
:: Vertical ³ Vertical º
:: Bottom Left Corner À Bottom Left Corner È
:: Bottom Right Corner Ù Bottom Right Corner ¼
:: Single Divider Top  Double Divider Top Ë
:: Single Divider Bottom Á Double Divider Bottom Ê
:: Single Divider Left à Double Divider Left Ì
:: Single Divider Right ´ Double Divider Right ¹
:: Single Divider Middle Å Double Divider Middle Î
:: Double Divider Top Ò Single Divider Top Ñ
:: Double Divider Bottom Ð Single Divider Bottom Ï
:: Double Divider Left Æ Single Divider Left Ç
:: Double Divider Right µ Single Divider Right ¶
::
:: Beep a Bullet ú
::
:: NOTE: The beep character doesn't actually take up a character space
:: on the screen like the other special characters. Use it only
:: at the end of a line of text to ensure proper alignment.
::
:: The example below displays double bordered text while beeping twice
:: (first beep is with the top border, second is with the bottom border).

 Echo.     ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»a
 Echo.     º Your Text Would Go Here º
 Echo.     ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼa
 Echo.
 Goto :EOF[/code]

Save this file in a safe location you can always get to. Most templates go in C:\Documents and Settings\All Users\Templates. However, this might be risky on a machine that kids or non technical people have access to (which is why Microsoft does not add .bat and .cmd to the Templates menu). Now you need to tweak the registry. Create a .reg file like so:

codeWindows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT.cmd\ShellNew]
"FileName"="X:\Folder\Subfolder\Template.cmd"[/code]
Where you have corrected the drive, the path, and the template file name to what you are using. But keep the double backslashes between your folders. Import the registry file into your registry. You need to reboot for the New template to first appear in the New menu. However, after it has been added, you may edit your template file at any time, without a reboot.

[quote="In my original post, I"]I believe that if you copy the template file to the default location (C:\Documents and Settings\All Users\Templates) that the registry file above could just be this:

codeWindows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT.cmd\ShellNew]
"FileName"="Template.cmd"[/code][/quote]EDIT: This technique is published all over the Internet, and comes up on most Google searches. However, I just tested it, and it simply does not work. Use the first example above, which does work. (It's what I use myself).

NOTE: You can only have one template for each file type. This also works for any file type, just change .cmd before \ShellNew in the registry to the extension you are interested in. If Windows cannot actually locate a template file, you will get an empty file of that file type.

To edit it in both Explorer and Opus, use Microsoft TweakUI ("Templates" page).[/quote]

Actually, TweakUI will not allow you to add either a .cmd template or .bat template file; this is why I posted my technique above.

Hello Ken,
Thanks very much for the above.
It's a beautiful idea !
I plan to make use of it.
It's a perfect place for many things, and you have provided simple and elegant access to all that's needed.
:slight_smile: LOL

Regards,
Porcupine :laughing: