views:

55

answers:

3
+1  Q: 

Port Bash to Batch

At my school I want to automate the process of telling the students to go to class and play a song five minutes before class starts at the end of lunch.

I wrote a Bash script that will play the announcement, a random song. After five minutes the script will fade out the music and kill VLC. I need this script run on Windows as the is the OS used for announcements. It doesn't need to be Batch, but I must be able to run it on Windows.

Here is the script that I wrote:

#!/bin/bash
#Copyright (c) 2010, Jason Cook
#All rights reserved.

#Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

 #Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 #Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 #Neither the name of the Jason Cook  nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#Set Arguments
song=$((RANDOM % 21))
volume_fade_counter=0

echo "Released under The BSD License"
echo

echo "11:55"
echo "Playing \"Get to Class\""
echo "Playing song number $song"
vlc /home/jason/Documents/Announcements-Lunch/get-to-class.mp3 /home/jason/Documents/Announcements-Lunch/$song.mp3 &

echo "Waiting for five minutes"
sleep 360

echo "Fading audio"
while [ $volume_fade_counter -le 100 ] ; do
 aumix -v -1
 volume_fade_counter=$(( $volume_fade_counter + 1 ))
done

echo "Killing VLC"
pkill vlc
exit
+4  A: 

Take a look at Cygwin, a free UNIX layer on top of Windows with a huge set of packages available. It includes bash to run bash scripts directly.

enzotib
A: 

Here's a vbscript (not tested, just directly translated)

Set WshShell = CreateObject("WScript.Shell")
Randomize
min=0
max=32767
song=CInt( (max-min+1)*Rnd+min )
volume_fade_counter=0
WScript.Echo "Released under The BSD License"
WScript.Echo "11:55"
WScript.Echo "Playing ""Get to Class"""
WScript.Echo "Playing song number " & song
strPath1="C:\home\jason\Documents\Announcements-Lunch\get-to-class.mp3"
strPath2="C:\home\jason\Documents\Announcements-Lunch\" & song &".mp3"
WshShell.Run("vlc "&strPath1&" "&strPath2,0)
WScript.Echo "Waiting for 5 min"
WScript.Sleep 18000
WScript.Echo "Fading audio"
Do While volume_fade_counter <= 100
    WScript.Run("aumix -v -1",0)
    volume_fade_counter=volume_fade_counter+1
Loop
Set WshShell = Nothing
WScript.Echo "Killing vlc"
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'vlc.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

usage:

C:\test> cscript //nologo myscript.vbs
ghostdog74
+1 for coding a bot named user131527 that does automatic language translations.
Dave
I hope to try this at lunch. I will tell you how/if it goes.
Jason
+1  A: 

Take also a look at MSYS http://www.mingw.org/wiki/msys

MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. It is intended to supplement MinGW and the deficiencies of the cmd shell.

Where I work we use it to run shell scripts on Windows.

Hanspeter Oberlin