I'd like to make a simple button that writes the paths of the selected items to a temporary m3u and then runs that file with the default program.
I tried the following and it's erroring out. I'd appreciate any help!
function OnClick(clickData)
{
var cmd = clickData.func.command;
var fsu = DOpus.FSUtil;
var tab = clickData.func.sourcetab;
var selItems = tab.selected;
if (selItems.count == 0) {
DOpus.Output("No items selected.");
return;
}
// Create an empty array to store the selected file paths
var filePaths = [];
// Iterate through selected items and add their paths to the array
for (var i = 0; i < selItems.count; i++) {
filePaths.push(selItems(i).realpath);
}
if (filePaths.length > 0) {
// Create the M3U playlist by joining the selected file paths
var playlistContent = filePaths.join("\n");
// Define the path for the temporary M3U file
var tempPlaylistPath = fsu.GetTempFileName("temp", "playlist", "m3u");
// Write the playlist content to the temporary file
fsu.WriteFile(tempPlaylistPath, playlistContent);
// Open the M3U playlist using CMD's start command
cmd.RunCommand('Run ' + '"start \"\" \"' + tempPlaylistPath + '\""', true);
}
}
You might need to close the file after writing to it and before sending it to the other program.
cmd.RunCommand('Run ' doesn't make sense unless you have a Run command installed somewhere. There isn't usually any Run command in Opus or Windows.
You can use the FileType ACTION=shellex command in Opus to do the equivalent of double-clicking a file. Before running it via cmd.RunCommand(...), first call cmd.ClearFiles() and then cmd.AddFile(tempPlaylistPath) to tell it which the file to run the command on.
If you still have errors, let us know the details of what happens and what the error is.
Thank you for the guidance! Here's the final script, working like a charm. I've modified to just write to the same temp file over and over instead of create a new one everytime
function OnClick(clickData)
{
var cmd = clickData.func.command;
var fsu = DOpus.FSUtil;
var tab = clickData.func.sourcetab;
var selItems = tab.selected;
if (selItems.count == 0) {
DOpus.Output("No items selected.");
return;
}
// Create an empty array to store the selected file paths
var filePaths = [];
// Iterate through selected items and add their paths to the array
for (var i = 0; i < selItems.count; i++) {
filePaths.push(selItems(i).realpath);
}
if (filePaths.length > 0) {
// Create the M3U playlist by joining the selected file paths
var playlistContent = filePaths.join("\n");
// Create temp playlist file and write playlistContent to it
var playlist = fsu.OpenFile("C:\Users\Shawn\AppData\Local\Temp\dopus_playist_from_selection.m3u", "wa");
playlist.write(playlistContent);
// Open the M3U playlist using CMD's start command
cmd.ClearFiles();
cmd.AddFile(playlist.path);
cmd.RunCommand("FileType shellex");
}
}
Trigger a file-type-defined event for the selected files. For example, you could use this to trigger the drag-and-drop event for a file from a button or hotkey. This is the default argument for the FileType command - you do not need to specify the ACTION keyword. Example:FileType drop