Difference between revisions of "VLC HowTo/Shut down the computer at the end of the playlist"

From VideoLAN Wiki
Jump to navigation Jump to search
m (vlc://quit ref)
Line 12: Line 12:
  
 
== Windows ==
 
== Windows ==
 
+
=== Bat File ===
 
Make a .bat file. The first command would be launching VLC, the second one is  
 
Make a .bat file. The first command would be launching VLC, the second one is  
 
<pre>SHUTDOWN -s -t 01</pre>.  
 
<pre>SHUTDOWN -s -t 01</pre>.  
Line 18: Line 18:
  
 
Launch {{VLC}} through the shortcut to the bat file.
 
Launch {{VLC}} through the shortcut to the bat file.
 +
 +
=== VBScript ===
 +
Make a .vbs file, copy in the code below and save. Drag and drop files onto the script file or double click the script to start it up.
 +
<pre>'By eyehawk78, posted on http://forum.videolan.org/viewtopic.php?f=16&t=70391
 +
 +
Dim oShell, FSO, FileData, vlc_path, video_dir, user, programs
 +
Dim files, seconds
 +
 +
force_shutdown = FALSE 'Set to true to force quit all other applications set to false otherwise
 +
 +
Function SelectFile()
 +
  Set file = CreateObject("UserAccounts.CommonDialog")
 +
  file.Filter = "Video Files (avi, mp4, mov, wmv, 3gp)|*.avi;*.mp4;*.mov;*.wmv;*.3gp;"
 +
  file.FilterIndex = 1
 +
  file.InitialDir = video_dir
 +
  InitFSO = file.ShowOpen
 +
 
 +
  If InitFSO = True Then 
 +
      SelectFile = file.FileName
 +
  Else
 +
      WScript.Quit
 +
  End If
 +
End Function
 +
 +
Sub InputError(ErrorString)
 +
  Wscript.Echo ErrorString
 +
  Wscript.Quit
 +
End Sub
 +
 +
files = ""
 +
 +
Set FSO = CreateObject("Scripting.FileSystemObject")
 +
Set oShell = CreateObject("WScript.Shell")
 +
 +
If Wscript.Arguments.Count > 0 Then
 +
  For Each FileData In Wscript.Arguments 
 +
      Set FileInfo = FSO.GetFile(FileData)
 +
      If InStr(FileInfo.Type, ".avi") or InStr(FileInfo.Type, ".mp4") or InStr(FileInfo.Type, ".mov") or InStr(FileInfo.Type, ".wmv") or InStr(FileInfo.Type, ".3gp") Then
 +
        files = files & " " & CHR(34) & FileData & CHR(34)
 +
      Else
 +
        InputError("File " & CHR(34) & FileInfo.Name & CHR(34) & " has an unrecognised file type - Must be of type .avi, .mp4, .mov, .wmv or .3gp")
 +
      End If
 +
  Next
 +
Else
 +
  user = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
 +
  video_dir = oShell.ExpandEnvironmentStrings("%VLC_SHUTDOWN_VIDEOS_DIRECTORY%")
 +
 +
  'If this if first run, we must save where the default video directory is
 +
 +
  If video_dir = "%VLC_SHUTDOWN_VIDEOS_DIRECTORY%" Then
 +
      video_dir = InputBox("Please input the directory where your Videos are kept." & vbcrlf & vbNewLine & "E.g. C:\Documents and Settings\User Name\My Documents\My Videos", "First Run", user)
 +
      If video_dir <> "" Then
 +
        strComputer = "."
 +
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 +
 +
        Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_
 +
 +
        objVariable.Name = "VLC_SHUTDOWN_VIDEOS_DIRECTORY"
 +
        objVariable.UserName = "<System>"
 +
        objVariable.VariableValue = video_dir
 +
        objVariable.Put_ 
 +
      Else
 +
        WScript.Quit
 +
      End If
 +
  End If 
 +
 
 +
  answer = 6
 +
 +
  'Loop while user wishes to add more files to playlist
 +
 +
  Do While answer = 6
 +
      files = files & " " & CHR(34) & SelectFile() & CHR(34)
 +
      answer = MsgBox("Would you like to add another file to the playlist?", 3, "Continue?")
 +
  Loop
 +
 +
  If answer = 2 Then
 +
      WScript.Quit
 +
  End If
 +
 
 +
End If
 +
 +
'If this if first run, we must save where the default VLC directory is
 +
 +
programs = oShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
 +
vlc_path = oShell.ExpandEnvironmentStrings("%VLC_SHUTDOWN_VLC_LOCATION%")
 +
 +
If vlc_path = "%VLC_SHUTDOWN_VLC_LOCATION%" Then
 +
  vlc_path = InputBox("Please input the directory where VLC program file is kept." & vbcrlf & vbNewLine & "E.g. C:\Program Files\VideoLAN\VLC", "First Run", programs)
 +
 
 +
  If vlc_path <> "" Then
 +
      strComputer = "."
 +
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 +
 +
      Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_
 +
 +
      objVariable.Name = "VLC_SHUTDOWN_VLC_LOCATION"
 +
      objVariable.UserName = "<System>"
 +
      objVariable.VariableValue = vlc_path
 +
      objVariable.Put_
 +
  Else
 +
      WScript.Quit
 +
  End If
 +
End If
 +
 +
vlc_path = CHR(34) & vlc_path & "\vlc.exe" & CHR(34) 'VLC directory location
 +
 +
seconds = InputBox("Please enter the number of seconds the system should delay before commencing shutdown", "Enter Number of Seconds", "5")
 +
If seconds <> "" Then
 +
  If IsNumeric(seconds) And seconds > 0 Then
 +
 +
      oShell.Run vlc_path & " " & files & " vlc://quit", 1, TRUE
 +
      'Execute shutdown command
 +
      If force_shutdown Then
 +
        oShell.Run "shutdown -s -f -t " & Round(seconds) & " -c " & CHR(34) & "Automatic Shutdown: Playlist Complete" & CHR(34)
 +
      Else
 +
        oShell.Run "shutdown -s -t " & Round(seconds) & " -c " & CHR(34) & "Automatic Shutdown: Playlist Complete" & CHR(34)
 +
      End If
 +
  Else
 +
      InputError("Input not a number or negative")
 +
  End If
 +
End If
 +
Wscript.Quit</pre>
 +
Note: Change line 6 to TRUE to force quit all other open applications.
  
 
== Linux ==
 
== Linux ==

Revision as of 14:31, 10 January 2010

This page describes how to switch off your computer automatically, when VLC has finished playing a file. Other "how to" pages

General idea

It is not a feature included in VLC media player but small scripts can do it for you.

Quit VLC

You can quit VLC media player after playback is finished, by adding

vlc://quit

to the playlist.

Shutdown

Windows

Bat File

Make a .bat file. The first command would be launching VLC, the second one is

SHUTDOWN -s -t 01

.

Add vlc://quit to leave.

Launch VLC media player through the shortcut to the bat file.

VBScript

Make a .vbs file, copy in the code below and save. Drag and drop files onto the script file or double click the script to start it up.

'By eyehawk78, posted on http://forum.videolan.org/viewtopic.php?f=16&t=70391

Dim oShell, FSO, FileData, vlc_path, video_dir, user, programs
Dim files, seconds

force_shutdown = FALSE 'Set to true to force quit all other applications set to false otherwise

Function SelectFile()
   Set file = CreateObject("UserAccounts.CommonDialog")
   file.Filter = "Video Files (avi, mp4, mov, wmv, 3gp)|*.avi;*.mp4;*.mov;*.wmv;*.3gp;"
   file.FilterIndex = 1
   file.InitialDir = video_dir
   InitFSO = file.ShowOpen
   
   If InitFSO = True Then   
      SelectFile = file.FileName
   Else
      WScript.Quit
   End If
End Function

Sub InputError(ErrorString)
   Wscript.Echo ErrorString
   Wscript.Quit
End Sub

files = ""

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")

If Wscript.Arguments.Count > 0 Then
   For Each FileData In Wscript.Arguments   
      Set FileInfo = FSO.GetFile(FileData)
      If InStr(FileInfo.Type, ".avi") or InStr(FileInfo.Type, ".mp4") or InStr(FileInfo.Type, ".mov") or InStr(FileInfo.Type, ".wmv") or InStr(FileInfo.Type, ".3gp") Then
         files = files & " " & CHR(34) & FileData & CHR(34)
      Else
         InputError("File " & CHR(34) & FileInfo.Name & CHR(34) & " has an unrecognised file type - Must be of type .avi, .mp4, .mov, .wmv or .3gp")
      End If
   Next
Else
   user = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
   video_dir = oShell.ExpandEnvironmentStrings("%VLC_SHUTDOWN_VIDEOS_DIRECTORY%")

   'If this if first run, we must save where the default video directory is

   If video_dir = "%VLC_SHUTDOWN_VIDEOS_DIRECTORY%" Then
      video_dir = InputBox("Please input the directory where your Videos are kept." & vbcrlf & vbNewLine & "E.g. C:\Documents and Settings\User Name\My Documents\My Videos", "First Run", user)
      If video_dir <> "" Then
         strComputer = "."
         Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

         Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_

         objVariable.Name = "VLC_SHUTDOWN_VIDEOS_DIRECTORY"
         objVariable.UserName = "<System>"
         objVariable.VariableValue = video_dir
         objVariable.Put_   
      Else
         WScript.Quit
      End If
   End If   
   
   answer = 6

   'Loop while user wishes to add more files to playlist

   Do While answer = 6
      files = files & " " & CHR(34) & SelectFile() & CHR(34)
      answer = MsgBox("Would you like to add another file to the playlist?", 3, "Continue?")
   Loop

   If answer = 2 Then
      WScript.Quit
   End If
   
End If

'If this if first run, we must save where the default VLC directory is

programs = oShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
vlc_path = oShell.ExpandEnvironmentStrings("%VLC_SHUTDOWN_VLC_LOCATION%")

If vlc_path = "%VLC_SHUTDOWN_VLC_LOCATION%" Then
   vlc_path = InputBox("Please input the directory where VLC program file is kept." & vbcrlf & vbNewLine & "E.g. C:\Program Files\VideoLAN\VLC", "First Run", programs)
   
   If vlc_path <> "" Then
      strComputer = "."
      Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

      Set objVariable = objWMIService.Get("Win32_Environment").SpawnInstance_

      objVariable.Name = "VLC_SHUTDOWN_VLC_LOCATION"
      objVariable.UserName = "<System>"
      objVariable.VariableValue = vlc_path
      objVariable.Put_
   Else
      WScript.Quit
   End If
End If

vlc_path = CHR(34) & vlc_path & "\vlc.exe" & CHR(34) 'VLC directory location

seconds = InputBox("Please enter the number of seconds the system should delay before commencing shutdown", "Enter Number of Seconds", "5")
If seconds <> "" Then
   If IsNumeric(seconds) And seconds > 0 Then

      oShell.Run vlc_path & " " & files & " vlc://quit", 1, TRUE
      'Execute shutdown command
      If force_shutdown Then
         oShell.Run "shutdown -s -f -t " & Round(seconds) & " -c " & CHR(34) & "Automatic Shutdown: Playlist Complete" & CHR(34)
      Else
         oShell.Run "shutdown -s -t " & Round(seconds) & " -c " & CHR(34) & "Automatic Shutdown: Playlist Complete" & CHR(34)
      End If
   Else
      InputError("Input not a number or negative")
   End If
End If
Wscript.Quit

Note: Change line 6 to TRUE to force quit all other open applications.

Linux

Make a .sh.

#! /bin/sh

vlc && shutdown -h now