Question about button & notepad

Hi all, I found a freeware app called notepad2. I'm going to use this as default handler for text editing.

I want a button that, when a file is selected than opens a file with notepad2. If no file is selected creates a txt file in the current directory and opens it.
Can this be done.?

I don't know if this info will help

[code]
Notepad2 3.0.20 =
(c) Florian Balmer 2004-2008
http://www.flos-freeware.ch

Command Line Switches

Notepad2.exe [/g ln[,col]] [/m[-][r|b] text] [/q] [/s ext] [/t] [/h]
[/x] [/c] [/b] [/n] [/p x,y,cx,cy[,max]|/p0] [/i]
[/f ini|/f0] [/?] [file]

file  File to open, can be a relative pathname, or a shell link.
      This must be the last argument, quotes are not necessary.
/g    Jump to specified position, a line of -1 means end of file.
/m    Match specified text (- last, r regex, b backslashes).
/q    Force creation of new files without prompt.
/s    Select syntax scheme associated with specified extension.
/t    Select default text scheme.
/h    Select Web Source Code scheme.
/x    Select XML Document scheme.
/c    Open a new Notepad2 window and paste the clipboard contents.
/b    Open a new Notepad2 paste board to collect clipboard entries.
/n    Always open a new Notepad2 window.
/p    Set window position to x,y with size cx,cy, optional max set
      to nonzero to maximize window; /p0 means use system default.
/i    Start as tray icon.
/f    Specify ini-file; /f0 use no ini-file (don't save settings).
/?    Display a brief summary about command line parameters.[/code]

I tried something with /q but didn't work

I use textpad but this should apply to notepad2 as well. Create and edit a button (see image below) but edit the path to something like "C:\Program Files\notepad2\notepad2.exe" {F!}

This works well for me, hope it helps.

Didn't work :frowning: . How about having opus create a txt file in current folder and then have notepad open it. How can I achieve that?

It should work. The help text you included mentions creating new files.

What happens when you run it? Can you show us the button you made?

I see. I have to define a filename, without filename it doesn't create one. So now i have this:

"D:\Appz\Notepad2\Notepad2.exe" /q untitled.txt Select untitled.txt Rename FROM untitled.txt =ask

So basically notepad creates a new file. I type something in, close the window. Notepad ask me to save it. I click yes. Then opus asks me to rename untitled.txt

Provided that there is no other untitled.txt this is safe I think. Or is this cumbersome?

But I want this only when no file(s) are selected. If a file is selected I just want to open it with notepad...Can this be done with one button or do i need tree button per se?

Forum member gieron. Made this button in button/toolbar section. Could i perhaps use something out of this

<?xml version="1.0"?> <button backcol="none" display="both" hotkey="ctrl+shift+N" textcol="none"> <label>Create File...</label> <tip>Create a new (empty) file</tip> <icon1>#newcommand</icon1> <function type="batch"> <instruction>runmode hide</instruction> <instruction>@set name = {dlgstringS|Enter the name of the file you want to create.|New File.txt}</instruction> <instruction>type NUL>>"{$name}"</instruction> <instruction>dopusrt /cmd SELECT DESELECTNOMATCH MAKEVISIBLE "{$name}"</instruction> </function> </button>

Try this instead:

@set FileName = {dlgstring|Enter a filename|Untitled.txt} "D:\Appz\Notepad2\Notepad2.exe" /q {$FileName}

[Edit: Fixed dlgstring typo. -Leo]

Thanks kenneth, this is exactly what i wanted. At firtst it didn't work but I presumed you typoed this {dlsgstring.... Changed it to {dlgstring... Works fine!! :smiley: :smiley:

Yeah my hunt-and-peck method isn't always the best!

PHPBB_IMPORT_WARNING CODE_NEAR_LI

Okay, I wrote a script inside of an Opus button that meets 100% of OpelOpus's wishes (plus some of my own). I have tried to make the script more general in nature, so other users can modify it for use with different text editors (or for that matter any program that can either open or create a new file with the same set of parameters).

DISCLAIMER: If you are going to give my button a try, please test it first in a test folder and with files that you have backed up, before using it in a production area. I cannot possibly test with all possible programs, so your mileage may vary. You assume all risk for anything that happens. Post any issues to this thread for now.

Here are the current rules for the script inside the button:[ol][li] It will only work for the first selected file.
[/li]
[li] It will ignore selected folders.
[/li]
[li] I believe that if you click the button and an Opus lister is not open to a real file system folder, then any newly created file will end up in %Temp%.
[/li]
[li] When you select a file and click the button, the specified program will attempt to open the selected file, using the specified parameter string—you will not be prompted for anything.

The specified program path is currently:

D:\Appz\Notepad2\Notepad2.exe

The program path can easily be changed, but do not add any quotes (even if your path contains spaces) over what the script already has (and leave the existing quotes in-place).

The specified program parameter string is currently:

/q ''%%FilePath%%''

The program parameter string can easily be changed in the script, but you must always specify the file path as shown above—the word "FilePath" surrounded by two percent characters at each end, and usually surrounded by quotes to handle paths and names containing spaces (see note).

NOTE: Due to limitations in the script technology I used, you cannot use the double quote character in your parameter string, so use two single quote characters instead. The script will replace the two single quote characters shown above at each end of %%FilePath%% with one double quote character during execution.
[/li]
[li] When you do not select a file and click the button, you will be prompted for a new file name and these rules will then also apply:[ul][li] The input box will display a default base name (i.e. no file path and no file extension), which you may accept as-is by pressing enter or clicking OK.
[/li]
[li] You may also optionally include any of the following information in the inputbox:[ul][li] A fully-qualified file path. If you do not include a fully-qualified path, the Opus source folder is used.[/li]
[li] A File Extension. If you do not include a file extension, the script default file extension is used (currently .txt but easily modified).[/li]
[li] A Base Name. If you do not include a base name at all, or you click Cancel on the Input dialog, nothing should happen—you have canceled the function.[/li][/ul][/li][li] The script will assemble a fully qualified path for the file to be created and pass it to the specified program via the program parameter string.[/li][/ul][/li]
[li] And as a bonus feature, I ensure the specified program always opens with system focus (i.e. on top of Opus).[/li][/ol]

I do have future plans for this project, but I want to ensure there are no serious issues with what I have first. Plus, I need time to work on it more. The future plans include:[ol][li] Convert this into a User Command that: has a template, accepts parameters, and gets listed in the Opus command list in the Advanced Command Editor command list. It is almost there as it is, but I try to test my user command more.
[/li]
[li] Allow you to specify different program parameters for opening a selected file versus creating a new file (since many programs will most likely use different parameters for each action).
[/li]
[li] Allow you to open several selected files at once. However, you will still only be able to create one file if no files are selected.
[/li]
[li] Allow the command to work when no lister is open (possible defaulting new file creation in your Documents folder, or in folder specified by passed parameter.) This is to facilitate hotkey usage.
[/li]
[li] Allow the command to work correctly when Opus is running from USB.[/li][/ol]
Notepad2.dcf (10.9 KB)

Wow Kenneth, I don't know what to say :astonished: . This is some effort you put in it..This button is even better...I really appreciate your help. Thanks! :smiley:

The truth is I put more effort into writing the post above than in writing the actual script. I already had several buttons and user commands that use most of the required script techniques. :wink:

Ken,

Thanks! This is a great script, and a big improvement on the button I've been using. :smiley:

Tony