<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://etcwiki.org/index.php?action=history&amp;feed=atom&amp;title=Using_.bat_files_for_random_actions</id>
	<title>Using .bat files for random actions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://etcwiki.org/index.php?action=history&amp;feed=atom&amp;title=Using_.bat_files_for_random_actions"/>
	<link rel="alternate" type="text/html" href="http://etcwiki.org/index.php?title=Using_.bat_files_for_random_actions&amp;action=history"/>
	<updated>2026-05-12T08:13:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://etcwiki.org/index.php?title=Using_.bat_files_for_random_actions&amp;diff=3705&amp;oldid=prev</id>
		<title>Ddxfish at 16:08, 25 July 2015</title>
		<link rel="alternate" type="text/html" href="http://etcwiki.org/index.php?title=Using_.bat_files_for_random_actions&amp;diff=3705&amp;oldid=prev"/>
		<updated>2015-07-25T16:08:31Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:08, 25 July 2015&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This code, if pasted into a .bat file will allow you to execute random programs (easy to modify for random sounds, or other random actions).  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This code, if pasted into a .bat file will allow you to execute random programs (easy to modify for random sounds, or other random actions).  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Windows Command Line DOS]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Usage of .bat random launcher==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Usage of .bat random launcher==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;make a directory to put it in, for example c:\random\&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;make a directory to put it in, for example c:\random\&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l7&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Create a new file named random.txt in the same directory.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Create a new file named random.txt in the same directory.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Add a list of random actions you want your computer to perform, each on its own line like the examples below.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Add a list of random actions you want your computer to perform, each on its own line like the examples below.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Microsoft Windows&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Software&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;NOTE:&amp;#039;&amp;#039;&amp;#039; The .bat file must be executed from the directory random.txt is in. If you want to change that, add its path on your computer in the bat before the filename random.txt. (e.g. c:\random\random.txt instead of random.txt)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;NOTE:&amp;#039;&amp;#039;&amp;#039; The .bat file must be executed from the directory random.txt is in. If you want to change that, add its path on your computer in the bat before the filename random.txt. (e.g. c:\random\random.txt instead of random.txt)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ddxfish</name></author>
	</entry>
	<entry>
		<id>http://etcwiki.org/index.php?title=Using_.bat_files_for_random_actions&amp;diff=1754&amp;oldid=prev</id>
		<title>Ddxfish at 06:00, 7 May 2009</title>
		<link rel="alternate" type="text/html" href="http://etcwiki.org/index.php?title=Using_.bat_files_for_random_actions&amp;diff=1754&amp;oldid=prev"/>
		<updated>2009-05-07T06:00:33Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This code, if pasted into a .bat file will allow you to execute random programs (easy to modify for random sounds, or other random actions). &lt;br /&gt;
[[Category:Windows Command Line DOS]]&lt;br /&gt;
==Usage of .bat random launcher==&lt;br /&gt;
make a directory to put it in, for example c:\random\&lt;br /&gt;
make a new text file, rename it random.bat , and edit it&lt;br /&gt;
Paste the code below into your .bat file&lt;br /&gt;
Create a new file named random.txt in the same directory. &lt;br /&gt;
Add a list of random actions you want your computer to perform, each on its own line like the examples below. &lt;br /&gt;
[[Category:Microsoft Windows]]&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE:&amp;#039;&amp;#039;&amp;#039; The .bat file must be executed from the directory random.txt is in. If you want to change that, add its path on your computer in the bat before the filename random.txt. (e.g. c:\random\random.txt instead of random.txt)&lt;br /&gt;
&lt;br /&gt;
You can have random.txt execute any action you want really, and if you are savvy with [[Windows_Command_Line:_Beginners_Guide|Windows Command Line]], you might want to check out the list of things you can do with this at the bottom of this article.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Random program launch batch code==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;random.bat&amp;#039;&amp;#039;&amp;#039; -- code is below, or download it here: [http://www.etcwiki.org/dl/random.bat random.bat] (right click and &amp;#039;Save Link As&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
Pulls a random program from random.txt, writes which one it picked to a file, then launches the program.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@Echo Off&lt;br /&gt;
For /F &amp;quot;tokens=2 delims=:&amp;quot; %%j in (&amp;#039;Find /C /V &amp;quot;&amp;quot; random.txt&amp;#039;) Do (&lt;br /&gt;
Set MOD=%%j&lt;br /&gt;
)&lt;br /&gt;
Set MOD=%MOD:~1%&lt;br /&gt;
&lt;br /&gt;
:LOOP&lt;br /&gt;
Set N=%random%&lt;br /&gt;
If %N% gtr 99 Set N= %N:~-2,2%&lt;br /&gt;
Set N=%N: 0=%&lt;br /&gt;
Set /A N=%N%%%%MOD%+1&lt;br /&gt;
&lt;br /&gt;
Set GRTS=&lt;br /&gt;
For /F &amp;quot;tokens=1-2 delims=[]&amp;quot; %%j in (&amp;#039;Find /N /V &amp;quot;&amp;quot; random.txt&amp;#039;) Do (&lt;br /&gt;
If &amp;quot;%%j&amp;quot;==&amp;quot;%N%&amp;quot; If not &amp;quot;%%k&amp;quot;==&amp;quot;&amp;quot; Set GRTS=%%k&lt;br /&gt;
)&lt;br /&gt;
If not defined GRTS GoTo :LOOP&lt;br /&gt;
&lt;br /&gt;
Echo. %GRTS% &amp;gt; lastactionlaunched.txt&lt;br /&gt;
start %GRTS%&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Set MOD=&lt;br /&gt;
Set N=&lt;br /&gt;
Set GRTS=&lt;br /&gt;
:: End_Of_Batch&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;random.txt&amp;#039;&amp;#039;&amp;#039; - make yours to do what you want it to do&lt;br /&gt;
&lt;br /&gt;
List of programs, or values that can be filled in for %GRTS% variable in the batch script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
c:\windows\notepad.exe&lt;br /&gt;
c:\myplaylist.m3u&lt;br /&gt;
echo outputting to text file &amp;gt; c:\textfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Important Notes==&lt;br /&gt;
* You must launch the .bat file from the same directory, or else you have to change the code to reflect the absolute path of the text file e.g. (c:\random\random.txt)&lt;br /&gt;
* Max lines is 99 in the random action file&lt;br /&gt;
&lt;br /&gt;
==What you can do with random .bat files==&lt;br /&gt;
*I use this mainly with Text-To-Speech programs. My setup is advanced, and when I say something to my computer, it can respond from a list of responses, all meaning the same thing but said in a different way. In other words, it doesnt have to say OK all the time, it can say OK, Affirmative, Roger that, etc so you dont get really bored with your TTS voices.&lt;br /&gt;
*Random Playlist Launch - you can easily just setup playlists in your random.txt file to have it launch one of your favorites at random.&lt;br /&gt;
*Set files to run at random times (advanced users) by using the at command and the variable %GRTS% from the code, schedule a task from a random list of times contained in random.txt.&lt;/div&gt;</summary>
		<author><name>Ddxfish</name></author>
	</entry>
</feed>