Sending ENTER in a button script or a batch file

Hi.

I'm trying to make a list of all videos I play. To do that, I have a batch file that get the filename and add it to a TXT file. After that, it call the system default player to run that video.

I created a button to call the batch file:

"C:\Programs\batch\GomPlayer - Histórico.bat" {allfilepath$}
@nodeselect

And the batch is:

@echo off
mode con cp select=1252

if "%~x1" == ".mkv" goto :MKV
if "%~x1" == ".mp4" goto :MP4
if "%~x1" == ".docx" goto :DOCX
if "%~x1" == ".txt" goto :TXT
if "%~x1" == ".aac" goto :AAC
if "%~x1" == ".wav" goto :WAV
if "%~x1" == ".srt" goto :SRT
if "%~x1" == ".jpg" goto :JPG
if "%~x1" == ".png" goto :PNG
if "%~x1" == ".bmp" goto :BMP
if "%~x1" == ".gif" goto :GIF
if "%~x1" == ".html" goto :HTML
if "%~x1" == ".rar" goto :RAR

goto :DEUERRO

@echo on

:MKV
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\GRETECH\GOMPlayer\GOM.exe" %1
goto :FIM

:MP4
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\GRETECH\GOMPlayer\GOM.exe" %1
goto :FIM

:DOCX
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" %1
goto :FIM

:TXT
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files\IDM Computer Solutions\UltraEdit\uedit64.exe" %1
goto :FIM

:AAC
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" %1
goto :FIM

:WAV
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\Winamp\winamp.exe" %1
goto :FIM

:SRT
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\Subtitle Workshop\SubtitleWorkshop.exe" %1
goto :FIM

:JPG
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\ACD Systems\ACDSee\ACDSee.exe" %1
goto :FIM

:PNG
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\ACD Systems\ACDSee\ACDSee.exe" %1
goto :FIM

:BMP
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\ACD Systems\ACDSee\ACDSee.exe" %1
goto :FIM

:GIF
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\ACD Systems\ACDSee\ACDSee.exe" %1
goto :FIM

:HTML
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" %1
goto :FIM

:RAR
dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"
"C:\Program Files\WinRAR\WinRAR.exe" %1
goto :FIM

:DEUERRO
echo. & echo/

:FIM

It's not possible to assign ENTER key to a shortcut key, using shortcut properties. But Opus can assign it, using a button.
I'd like to do that simply using ENTER key. So, how to override the default behavior of it to call the batch file and not the default player?

It works this way, but only if I press ENTER on a video file or other file type listed above.

Problem is that if I press ENTER on a folder or anything else different from the file types above, nothing happens.
Because I can't send ENTER to the pipe.

In other words, how to press ENTER in a video file and it invoke the batch file and not the system default player instead?
I thought that a script for the button, checking the file type and then sending ENTER, or something.

I'm an old user of Directory Opus. My version is still 9.5.6.0.
And I'm an old sailor, navigating a Windows 7.

Thanks.

A much easier way is to go to Settings > File Types, then change the Double-Click event for the types you want to override. That's what gets run when you push enter on a file.

1 Like

At Settings > File Types, I have two groups:

DOpus - Histórico do Gom - File Types 1

DOpus - Histórico do Gom - File Types 2

Both require a script to handle the files:

DOpus - Histórico do Gom - File Types 3

I'm a little bit lost here.

How to press ENTER on a movie file, i.e. .mp4, and send it's name to a txt file that store the history of the program used, if a video player or a picture browser?
Of course, the file must be opened, after that, by it's default handler.

In other words, a txt file that lists all video and pictures recently opened.

And, if it's a folder or other file type not listed, behaves like a real folder or something else.

Double click is not the case. I avoid to use the mouse as possible as I can.

And last question, I can't see the difference between Standart Function and MS-DOS Batch Function.

Thanks.

The Double-Click event is treated the same as an Enter event, so you don't need the mouse at all. (I also try to use the keyboard as much as possible...)

You do indeed need to define some kind of script to achieve what you want: Get the selected movie file's name, open your txt file, append the latest name, close the txt file, then open the movie file in your player. (If I understood you correctly.) Your best bet would be a bit of JScript.

Use "Standard Function, Opus or external"; that's where the powerful DO scripting happens. MS DOS Batch functions are mainly useful for external scripting. It might be a good idea to familiarize yourself with the general concepts, perhaps starting here: Creating your own buttons [Directory Opus Manual]

Have fun and good luck :smiley:
MartO

1 Like

I put a MS-DOS line but it could not receive the filename:

dir %1 /b >> "D:\Programas\GomPlayer - Histórico.txt"

And send the list of all current folder to the TXT file.
Even so, it didn't run the video file with the player at the end.

Yes, you did understand the task.
I put this code:

var nomeArquivo = WScript.Arguments(0);

var caminhoArquivoTexto = "D:\\Programas\\GOMPlayer - Histórico.txt";

var fso = new ActiveXObject("Scripting.FileSystemObject");

var arquivoTexto = fso.OpenTextFile(caminhoArquivoTexto, 8, true);

arquivoTexto.WriteLine(nomeArquivo);

arquivoTexto.Close();

But I don't know how to receive the filename. The list of arguments for selected files are {file}, {file$}, {allfile}, etc. I don't know how to use them.
And it also has to invoke the video player at the end.

Thanks for the tip. I know that I must study a little more and understand scripting.

:+1:

Try this JScript (very quick and dirty, of course):

function OnClick(data)
{
	var movie = data.func.sourcetab.selected_files(0); // first selected file

	var fsu = DOpus.FSUtil();

	var listFile = fsu.OpenFile("C:\\your\\path\\list.txt", "wo"); // open or create for writing
	if (!listFile.error) {
	    listFile.Seek(0, "e"); // end of file
		listFile.Write("hello " + movie.name + "\n"); // include newline
	}
	listFile.Close();

	var cmd = data.func.command;
	cmd.RunCommand("\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" \"" + movie.path + "\\" + movie.name + "\"");
}
1 Like

Your script triggered an error that "Windows cannot find 'function'. Be sure the name was typed correctly and try again".

I'm not sure if the error I got it's because I use an old version of Directory Opus.
I'm using 9.5.6.0 version and Windows 7.

Scripting wasn't introduced until version 11...

I have some scripts working here.
This is an example:

@nodeselect
@confirm Do you want to move all files to root folders ?|Yes|No

Rename PATTERN * TO *

@script vbscript
Dopus.OutputString "Script: Files2Root - By Albator V"
Dim ParentPath

Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName )
 If fIsFolder then
  ParentPath = strFullPath & "\" & strFileName
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFSO.GetFolder(ParentPath) 
  Set colSubfolders = objFolder.Subfolders

  For Each objSubfolder in colSubfolders 
   FolderLoop(ParentPath & "\" & objSubfolder.Name) 
  Next 

  Set colSubfolders = Nothing 
  Set objFolder = Nothing 
  Set objFSO = Nothing
 Else
  Dopus.OutputString "Select first some folders."
 End If
End Function 

Function FolderLoop(Path) 
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objFolder1 = objFSO.GetFolder(Path) 
 Set colSubfolders1 = objFolder1.Subfolders 
 Set colFiles = objFolder1.Files 
 
 For Each objFile in colFiles 
  Fichier = Path & "\" & objFile.Name
  objFSO.MoveFile Path & "\" & objFile.Name, ParentPath & "\" 
  Dopus.OutputString "Move " & fichier
   Dopus.OutputString "to " & ParentPath
 Next 

 For Each objSubfolder1 in colSubfolders1 
  FolderLoop(Path & "\" & objSubfolder1.Name) 
 Next 

 objFSO.DeleteFolder(Path) 
 Dopus.OutputString "Delete " & Path
 Set colSubfolders1 = Nothing 
 Set objFolder1 = Nothing 
End Function 

But I don't know the right commands to do what I want...
:face_with_diagonal_mouth:

Opus 9 supported rename scripts, and that could be (ab)used as a way to run script code which did other things, but it won't work for the script in question as it requires the more general scripting API and objects that Opus 9 didn't have.

So, is there no solution for a simple task like that?
It's just to, pressing ENTER key, send the filename to a TXT file and play this video file.

Assigning a hotkey, I can do it. But not using ENTER key.

DOPus has a lot of resources.
Even old versions are far better than similar and alternatives tools.
I still guess it's possible.

The solution is using a version of Opus that’s newer than 15 years old, so you have scripting support. :slight_smile: Opus 9 is very limited compared to current versions.