Help with a Batch Macro

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Grapefruits
Posts: 7
Joined: 27 May 2018 11:43

Help with a Batch Macro

#1 Post by Grapefruits » 30 Aug 2018 16:46

Hey everyone. So right now, I have a Batch macro "with arguments", of which I took the form from viewtopic.php?f=3&t=2518. The macro is this:

Code: Select all

set ac=^<^>
set MUSIC=for /L %%n in (1 1 2) do if %%n==2 (%\n%
      for /F "tokens=1 delims=, " %%1 in ("!argv!") do (%\n%
         set "argument1=%%1"%\n%
         set prevmusic=!argument1!%\n%
         ( echo Set Sound = CreateObject("WMPlayer.OCX.7"^^)%\n%
           echo Sound.URL = "!argument1!.mp3"%\n%
           echo Sound.settings.volume = 100%\n%
           echo Sound.settings.setMode "loop", True%\n%
           echo Sound.Controls.play%\n%
           echo While Sound.playState !ac! 1%\n%
           echo WScript.Sleep 100%\n%
           echo Wend%\n%
           ^) ^>Music.vbs%\n%
         start /min Music.vbs%\n%
      ) %\n%
) ELSE setlocal enableDelayedExpansion ^& set argv=,
It creates a .vbs file that plays music on loop, and works fine when I do %MUSIC% JazzBeat2. However, I have a txt file with many commands in it such as:

Code: Select all

%MUSIC% JazzBeat3
%MUSIC% JazzBeat2
I have another script which reads the aforementioned txt line by line, and it's supposed to execute each line (%MUSIC% JazzBeat3, ect) by means of :

Code: Select all

!Line1!

So if Line1 is equal to "%MUSIC% JazzBeat3" on the txt file, it should play Jazzbeat3. However, it says that "%MUSIC% is not recognized". How can I solve this?


Thank, Grapefruits,

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help with a Batch Macro

#2 Post by Ed Dyreen » 31 Aug 2018 03:43

Post the complete code also batch2, I don't like guessing what you are doing.

batch1 seems to accept only a single parameter %%1 and %MUSIC% seems to handle also only a single parameter.
then batch1.CMD "mySongPath/mySong.MP3" should simply work.

You can execute %MUSIC% JazzBeat3 from batch2 in two ways:

-either %MUSIC% expands to batch1.CMD in which case you want to prepend CALL to %MUSIC% so control is returned to batch2 after execution of batch1.

-or it is the macro defined in batch1.

Post the complete code also batch2, I don't like guessing what you are doing.

Why are you using two different scripts instead of just one ?

Post Reply