Running several scripts

I have different scripts creating playlists (genre). On changes of my library I'd like to run them all in one button for fast update.

How can I execute them (there're user-commands)? Also they should run one after each other, because once all musicfiles were read on first script, the next script runs pretty fast (cached).

If they're user commands, just set up a button that calls one command after the other.

That's why I asked, because it doesn't work that way. Only first script will be executed, but all following ignored.

I can't reproduce that here. I created two test scripts which both implement two user commands. Each user command simply outputs a line to the script log. I then set up a button that runs all four user commands in sequence, and on clicking it the script log shows that each one was executed in turn.

Can you post your scripts and button so that I can try to repeat it?

(Leo adding to Jon's post: Same here. Screenshot of my test:)

I can confirm that running two user commands with variations of tbone's SelectEx Script Addon from a button doesn't work. Only the first one will be executed. Here are two examples:

User command 1:var cmd = DOpus.Create.Command var jsFilter = ""+ "if (item.metadata == 'audio'){ "+ "var year = new String(item.metadata.audio['mp3year']);"+ "var int = parseInt(year);"+ "if (int < 1980) return false;"+ "}"; cmd.RunCommand('Delete coll://Oldies REMOVECOLLECTION=auto QUIET') cmd.RunCommand('SelectEx LINEAR '+ 'PATH="'+DOpus.FSUtil.Resolve('/mymusic')+'" RECURSE JSFILTER="'+jsFilter+'" '+ 'ITEMCOUNTPERC=100 '+ 'COPYTOCOLL=Oldies '+ 'TOFILE="'+DOpus.FSUtil.Resolve('/temp\\Oldies.m3u')+'" '+ 'COMMANDS=Go coll://Oldies') cmd.RunCommand('Set SORTBY=+mp3year(0)')
User command 2:var cmd = DOpus.Create.Command var jsFilter = ""+ "if (item.metadata == 'audio'){ "+ "var genre = new String(item.metadata.audio['mp3genre']);"+ "if (genre.indexOf('Pop') !=-1) return false;"+ "}"; cmd.RunCommand('Delete coll://PopColl REMOVECOLLECTION=auto QUIET') cmd.RunCommand('SelectEx LINEAR '+ 'PATH="'+DOpus.FSUtil.Resolve('/mymusic')+'" RECURSE JSFILTER="'+jsFilter+'" '+ 'ITEMCOUNT=1000 '+ 'COPYTOCOLL=PopColl'+ 'TOFILE="'+DOpus.FSUtil.Resolve('/temp\\PopColl.m3u')+'" '+ 'COMMANDS=Go coll://PopColl') cmd.RunCommand('Set SORTBY=+mp3genre(0)')

Please post the whole script so we can see exactly what's going on.

It's already the whole code. tbone's SelectEx Script Addin must be installed to make the code working from a Script function button. Let's call user command 1 "Oldies" and user command 2 "Pop" then the button code would simply be this:

Oldies Pop

It's not the whole code, because to make a user command from a script requires at least an OnInit function and an OnCommand function.

Essentially the button should run the SelectEx command with various arguments twice. The jscript snippet is only needed to define the jsFilter argument. The user commands are not created by this code but via Customize=>Commands=>User defined Commands.

@Sasa
Try adding the NOFAIL switch to each SelectEx execution. It might help.
If it does, it could be there is the wrong code returned by SelectEx and the combination of switches you're using.

A sequence of DO commands will be aborted once any of the command returns "failure".
NOFAIL will switch SelectEx into not returning "failure" ever, regardless of what failed or what bug is still in there.

[quote]Try adding the NOFAIL switch to each SelectEx execution.[/quote]Thanks for your input tbone. Unfortunately it makes no difference here.

The original post was about user commands implemented via scripts, so I'd say whatever you're seeing is a different issue and you should open a new thread for it.

I'm sure what Sasa tries to do is exactly what I posted here because I created the SelectEx button codes to create playlists for him in the german forum.

Ok well either way, we need more information to look into it. Post the full scripts and the full buttons. I'm not sure why you won't but it's very frustrating :frowning:

Sorry but the full script is tbone's SelectEx Script Addon. It provides the command SelectEx with several arguments. For the JSFILTER argument you can provide a js-snippet. The code I provided defines this argument and afterwards runs the SelectEx command with several additional arguments. The code can be reduced to this:

[code] var cmd = DOpus.Create.Command
var jsFilter = ""+
"if (item.metadata == 'audio'){ "+
"var year = new String(item.metadata.audio['mp3year']);"+
"if (year.indexOf('198')!=-1) return false; /do not filter/"+
"}";

cmd.RunCommand('SelectEx LINEAR '+
	'PATH="'+DOpus.FSUtil.Resolve('/mymusic')+'" RECURSE JSFILTER="'+jsFilter+'" '+
	'ITEMCOUNT=1000 '+
	'COPYTOCOLL=PopCollection '+
	'TOFILE="C:\\Temp\\PopCollection.m3u" '+
	'COMMANDS=Go coll://PopCollection')

[/code]

The thread so far seems both very complicated and missing details (or is assuming Jon or I will know things that we don't).

Jon & I have both shown that you can have a button which runs several script-commands one after another and they all run.

Is that what this thread is about, or something else?

Can someone who is seeing the problem simplify things into a simple example of what they think should work but does not work?

A simple example should not involve SelectEx if possible, since that is a huge, complex script which we are not intimately familiar with, and the problem may be with how you're using SelectEx rather than Opus.

The example should give us everything we need in one post, and should only need to be a few lines of script/button code if you think the problem is as simple as "Opus only runs the first command when asked to run several", or similar. If the problem is more complex than that, then I don't think the problem has been fully described yet.

My initial post refers using SelectEx and the playlist scripts (which kundal postet above). This combination doesn't work.

I think it's the SelectEx Script not behaving as expected in this special case.

@Sasa: You can create a script function button or user defined command that does what you want by simply merging the code. This works fine here:

[code] var cmd = DOpus.Create.Command
var jsFilter = ""+
"if (item.metadata == 'audio'){ "+
"var year = new String(item.metadata.audio['mp3year']);"+
"var int = parseInt(year);"+
"if (int < 1980) return false;"+
"}";
cmd.RunCommand('Delete coll://Oldies REMOVECOLLECTION=auto QUIET')
cmd.RunCommand('SelectEx LINEAR '+
'PATH="'+DOpus.FSUtil.Resolve('/mymusic')+'" RECURSE JSFILTER="'+jsFilter+'" '+
'ITEMCOUNTPERC=100 '+
'COPYTOCOLL=Oldies '+
'TOFILE="'+DOpus.FSUtil.Resolve('/temp\Oldies.m3u')+'" '+
'COMMANDS=Go coll://Oldies')
cmd.RunCommand('Set SORTBY=+mp3year(0)')

var jsFilter = ""+
	"if (item.metadata == 'audio'){ "+
	"var genre = new String(item.metadata.audio['mp3genre']);"+
	"if (genre.indexOf('Pop') !=-1) return false;"+
	"}";
cmd.RunCommand('Delete coll://PopColl REMOVECOLLECTION=auto QUIET')
cmd.RunCommand('SelectEx LINEAR '+
	'PATH="'+DOpus.FSUtil.Resolve('/mymusic')+'" RECURSE JSFILTER="'+jsFilter+'" '+
	'ITEMCOUNT=1000 '+
	'COPYTOCOLL=PopColl '+
	'TOFILE="'+DOpus.FSUtil.Resolve('/temp\\PopColl.m3u')+'" '+
	'COMMANDS=Go coll://PopColl')
cmd.RunCommand('Set SORTBY=+mp3genre(0)')

[/code]

Thanks. And also less user commands :slight_smile:.