.VBS get current Windows Media Player song name - vbscript

Is it possible to get the name of the current song playing in WMP with a VBS script? My goal is to have a .txt file that contains the name of the currently playing song. I'm using a livestream program (OBS) which can display text from a file, and since so many people ask me for my playlist while streaming, I'd like to have OBS display the name of the current song. To accomplish this, I'm just going to have it change the "Current Song" text to whatever is in currentsong.txt located on my Desktop, but I just don't know how update that txt to contain the current song.
I've searched around on Google and I haven't been able to find any way to get the current MWP song :(
Help please :(

Note: Retrieving information on a sequence can be done only when the load status "Transitioning" is reached.
Option Explicit
Dim Sound,Name,NameLog,fso,ws
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("wscript.Shell")
Set Sound = CreateObject("WMPlayer.OCX.7")
Sound.URL = "C:\FaceSong.mp3"
'Disable the sound
Sound.settings.mute = True
Sound.Controls.play
'Note: Retrieving information on a sequence can be done only when the load status "Transitioning" is reached.
While Sound.playState = 9
Name = Sound.currentMedia.getItemInfo("Name")
NameLog = Name & ".txt"
if fso.FileExists(NameLog) Then
fso.DeleteFile NameLog
end If
MsgBox Name,VbInformation,Name
Call WriteLog(Name,NameLog)
Wend
ws.run NameLog
'***********************************************************************************************
Sub WriteLog(strText,LogFile)
Dim fs,ts
Const ForAppending = 8
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(LogFile,ForAppending,True)
ts.WriteLine strText
ts.Close
End Sub
'************************************************************************************************

You need to either read Media Player's documentation (so when you looked on the internet you did look at MSDN.com which is where it lives, like all Microsoft's documentation.?). If you have a programming IDE (like VBA in Office) then use it's object browser.
Start an office app, press Alt + F11, then F2.
Right click somewhere and choose References add Windows Media Player from list. Change drop down from All Libraries to just Media Player.
You have a property for filename. And a method to get any info on the song.
Property FileName As String
Member of MediaPlayer.MediaPlayer
Returns or sets the current file name and path
and
Function GetMediaInfoString(MediaInfoType As MPMediaInfoType) As String
Member of MediaPlayer.MediaPlayer
Returns an Information String for the Media
Remember VBS doesn't have access to the type library so you have to use constant's values instead of constant's names. So in the above you woulduse 8 and not mpClipTitle to get the title.

Related

Error Saving File in Document Folder of Library

I am writing an HTA file with VBScript as the scripting language. I have a function where the user is prompted to choose the folder in which they would like to save a document. I didn't write this code myself, but instead borrowed it from here.
Function SelectFolder(myStartFolder)
Dim objFolder, objItem, objShell
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Select Folder to Save New File", 0, myStartFolder)
If IsObject(objFolder) Then SelectFolder = objFolder.Self.Path
End Function
I call this function in another one in order when I make the file and prompt the user to choose where to save it:
Sub Example()
Dim destPath, destFile, objWorkbook
destPath = SelectFolder(libPath)
destPath = destPath & "\Sample Export"
Set destFile = CreateObject("Excel.Application")
Set objWorkbook = destFile.Workbooks.Add()
objWorkbook.SaveAs(destPath)
(code to edit excel file)
End Sub
Example() works fine except when someone chooses to save their document in one of the four default libraries in Windows (Documents, Music, Pictures, Videos). In that case, I receive an error saying "The file could not be accessed" and indicating the error is at the line that says "objWorkbook.SaveAs(destPath)". The error box then gives me the following suggestions:
Make sure the specified folder exists
Make sure the folder that contains the file is not read-only
Make sure the file name does not contain any of the following characters: < > ? { } : | or *
Make sure the file/path name doesn't contain more than 218 characters.
The error occurs when I open the HTA file and click a button calling Example(), which then opens a dialog box to ask the user to choose the file location. When Documents, Music, Pictures, or Videos is chosen, a "Script Error" box pops up with the error message listed above. I am not familiar enough with VBScript to know what the problem is exactly. I would appreciate any suggestions as to what to do.
I don't know exactly what the solution to the above issue was. However, I noticed that the path I pass to SelectFolder had a typo in it. libPath was supposed to be to the %userprofile% from the environment variable. However, I had pluralized "userprofiles" so that it was %userprofiles% instead. This took me to somewhere that looked right but wasn't. I fixed the typo and now BrowseForFolder takes me to C:/Users/*username* like it's supposed to. It turns out that I was being sent to the Desktop location because of the fourth argument in BrowseForFolder, instead of the user profile like I wanted.

VBA - Export individual PowerPoint slides into PDF files, named by content field

I have about 15 different slide decks, that contain 3-4 slides each. Each deck is comprised of "certificates" to be broken out and given to each individual recipient, who is named on the certificate. This process is repeated every month.
ideally, I would like to enable a VBA script to extract each sheet to save as (or print as) a PDF, and save the file with the name of the recipient named on the slide... is this possible?
The best I have found is this code, (which doesn't work on my mac, but works fine on a VM) which DOES separate the slides into PDF's, but I would like the naming to be changed.
Any help would be greatly appreciated!!
Sub ExportSlidesToIndividualPDF()
Dim oPPT As Presentation, oSlide As Slide
Dim sPath As String, sExt As String
Set oPPT = ActivePresentation
sPath = oPPT.FullName & "_Slide_"
sExt = ".pdf"
For Each oSlide In oPPT.Slides
i = oSlide.SlideNumber
oSlide.Select
oPPT.ExportAsFixedFormat _
Path:=sPath & i & sExt, _
FixedFormatType:=ppFixedFormatTypePDF, _
RangeType:=ppPrintSelection
Next
Set oPPT = Nothing
End Sub
Edit for further clarification:
I'm forced to run the script in my Windows Virtual Machine, and when I do that, I'm losing all of my formatting that I set up in my slides, created in office '11 (which is one of my big reasons to export to PDF in the first place).
A little more about my project:
1. I am compiling a couple thousand lines of "actions" (data), to determine a winner for a recognition award, based on criteria for 4 different award categories, for 12-15 different executives.
2. Results are tallied, then I retrieve the winners information (name, ID, and the same for their manager and executive) from an LDAP directory. Then put into a csv for mail-merge at later step.
3. A Template slide deck is used for all slides, (12-15 executives have 3-4 winners each).
4. Individual PDF certificates are created from those slides.
5. Congratulatory message is drafted, fields pulled from prepared csv for mail-merge, and then exported to outlook 2011 outbox (client offline).
6. I attach each individual certificate to each message manually in the outbox.
7. Send.
I have compiled sample set of the files linked here: Recognition Files (Sample)
On each slide there are one or several shapes. For the sake of illustration, assume that the recipient's name is in the first shape.
Sub ExportSlidesToIndividualPDF()
Dim oPPT As Presentation, oSlide As Slide
Dim sPath As String, sExt As String
Set oPPT = ActivePresentation
sExt = ".pdf"
For Each oSlide In oPPT.Slides
'## Retrieve the recipient's name from the shape and append it to the exported path:
sPath = oPPT.FullName & oSlide.Shapes(1).TextFrame.TextRange.Text
i = oSlide.SlideNumber
oSlide.Select
oPPT.ExportAsFixedFormat _
Path:=sPath & sExt, _
FixedFormatType:=ppFixedFormatTypePDF, _
RangeType:=ppPrintSelection
Next
Set oPPT = Nothing
End Sub
It may be more complicated, depending on how the slides are configured (e.g., if there is a shape that contains the name and other text, you will need a function to parse out the proper name and omit the rest, etc.
Provide more detail, about the problem if you need further assistance.

Change iTunes Track Comment on MacOS

I've written the below code in vba to change comments in iTunes tracks in a Windows environment:
Dim iTunes As New iTunesApp
Dim library As IITLibraryPlaylist
Dim tracksByArtist As IITTrackCollection
Dim xSearch As String, xComment As String
Dim track As IITFileOrCDTrack
Dim i As Long, j As Integer
Set library = iTunes.LibraryPlaylist
xComment = "myComment"
For i = 1 To NumberOfSongInItunes 'Number of songs in library
If xArray(9, i) = "Target" Then 'xArray holds information that i've previously read from the library or xml file
xSearch = "Artist Name " & "Album " & "Track Name"
Set tracksByArtist = library.Search(xSearch, 0)
For Each track In tracksByArtist
track.Comment = xComment
Next
End If
Next
Set iTunes = Nothing
I've been playing around in Xcode with ITLibrary, ITLibAlbum, ITLibArtist, etc. but with no success. Any ideas? Preferably not using applescript as it would be slow.
I'm not sure how well this fits in with what you're looking for, but the Scripting Bridge framework is always and option. The example below just changes the comment on which ever track is currently playing, but you can use iTunes.h and Scripting Bridge to do basically what ever you want with iTunes and its tracks.
#import <ScriptingBridge/ScriptingBridge.h>
#import "iTunes.h"
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:#"com.apple.iTunes"];
[[iTunes currentTrack] setComment:#"I just added this cool comment to the current track!"];
There are recently generated copies of some of the Scripting Bridge headers on github, but I recommend that you compile your own to make sure everything is up to date. Instructions can be found here https://developer.apple.com/library/mac/DOCUMENTATION/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html
Basically, to generate iTunes.h you'll need to run the following command.
sdef /Applications/iTunes.app | sdp -fh --basename iTunes
there is no public API for that. you would have to open the XML file and edit it. It is prone to break though

Save images in Outlook 2007

Programmatically, of course.
Having already asked this question on superuser, I'm looking at writing a simple macro to pull down the displayed image in an HTML message (email or feed) in outlook 2007, and allow me to save it to disk.
Unfortunately, I havent been able to find where in the OL object model I can reference either linked images, or the html content itself. Finding attached files is easy, its the linked/displayed images that is my issue.
Any help? Of course, if you have a better non-programmatic answer, I'll be glad to see that - over on superuser, of course...
This is based on the MSDN docs. I don't have Outlook to test it.
Assuming you have an email message open, you can call GetInspector method on the MailItem instance that you have & use its HTMLEditor property to get handle to the DOM.
From here on, you can call regular methods such as document.Images to get handle to all the image elements. I don't know, how one can save it locally to a disk but I am sure, there must be some method to do it.
I had a second look at shahkalpeshs answer and came up with the following solution:
(Written in Outlook 2003)
Option Explicit
Private Sub getImages()
Dim xmlhttp_ As xmlhttp
Dim htmldoc As Object
Dim currentImage As Object
Dim currentResponse() As Byte
Dim startTime As Date
Dim maxTime As Long
Dim pathFolder As String
Dim pathFull As String
Dim nrFile As Integer
pathFolder = "C:\YourFolder\Images\" '"(small fix for stackoverflow syntaxhighlighter)
maxTime = 30 ' max time to load 1 File in seconds '
If Me.ActiveWindow.CurrentItem.GetInspector.EditorType = olEditorHTML Then
Set htmldoc = Me.ActiveWindow.CurrentItem.GetInspector.HTMLEditor
Set xmlhttp_ = New xmlhttp
For Each currentImage In htmldoc.images
xmlhttp_.Open "GET", currentImage.src
If Left(currentImage.src, 8) <> "BLOCKED:" Then
xmlhttp_.Send
startTime = Now
pathFull = pathFolder & currentImage.nameProp
pathFull = Replace(pathFull, "?", vbNullString)
pathFull = Replace(pathFull, "&", vbNullString)
Do While xmlhttp_.readyState <> 4
If DateTime.DateDiff("s", startTime, Now) > maxTime Then Exit Do
DoEvents
Loop
If xmlhttp_.readyState = 4 Then
If Dir(pathFull) <> "" Then Kill pathFull
nrFile = freeFile
Open pathFull For Binary As #nrFile
currentResponse = xmlhttp_.responseBody
Put #nrFile, , currentResponse
Close #nrFile
End If
End If
Next currentImage
End If
Set xmlhttp_ = Nothing
Set currentImage = Nothing
Set htmldoc = Nothing
End Sub
This code will download all the images that are displayed in your ActiveWindow and save them in a folder.
You will need to add a Reference to Microsoft XML (any version >= 2.6 should work) through Tools->References in the VBA Editor
If you want to, you can also set a Reference to the Microsoft HTML Object Library and change:
Dim htmldoc As Object
Dim currentImage As Object
to:
Dim htmldoc As HTMLDocument
Dim currentImage As HTMLImg
Regarding your comment:
#marg, Thanks for the detailed response. I still cant believe the solution has to be so convoluted - the image is already displaying, why should I have to download it again? And what if I want to save only a single image? (In Outlook 2003, you were able to right click on the image and select save as... now no more.) Since this is the closes to an actual workable solution, and since there doesnt seem to be any better solution in current Outlook - i'm giving you the bounty...
I don't have 2007 to look for a non-programming solution.
I do not believe that the MailItem Object (CurrentItemin my solution is a MailItem) differs much between the versions (but I base that assumption on 0 % research :D) and I was not able to locate the direct local path where the displayed images are stored even though I am pretty sure they should be in your browsers cache-folder. Crawling your folder for a file with the name currentImage.nameProp and copying it to your destination folder would be an alternative solution. Simply redownloading the image should not be that bad :D

Progress bar in VB 6.0 from Transcoding process in FFMPEG

firts excuse me for my English it`s super Freak. Sorry
I have a big problem , i need finish my applicatión in VB6.0 for a test in my High Schooll and i can`t find the solution, My app open a FFmpeg.EXE file which open a cmd window Prompt and start a trascoding process, i need link the last line generated into the Prompt of the CMD window (Or top Bottom) , in this line exists Values what change , in this trascoding process the result are bit Rates , which fluctuates acording to others var.
The idea it´s what into the form of my app i can read this line in real time to bulid a progress bar (File Size/Bitrate average)=time to process.
Can you help me. Thanks for the answer....
Put a reference to Windows Scripting Host Object Model and try this snippet
Option Explicit
Private Sub Command1_Click()
Dim oExec As WshExec
Dim sRow As String
With New WshShell
Set oExec = .Exec("tasklist.exe")
End With
Do While oExec.Status = WshRunning
sRow = oExec.StdOut.ReadLine
If InStr(1, sRow, "vb6.exe", vbTextCompare) > 0 Then
MsgBox sRow, vbExclamation
End If
Loop
End Sub
Basicly try executing FFmpeg.EXE and ReadLine until you find some key text.
Send the output to a textfile then read this textfile.
Should look something like this:
ping >e:\test.txt
Where ping is the FFmpge.EXE and e:\test.txt the output textfile
rdkleine
I read your answer and this is great work very good , only that it shows in the log a death value "text", and i need the value of fluctuates bitrates of conversion , which changes in real time in the prompt of the cmd window. i'm trying now with the source code of wqw , i'm working in there.
Thak's for your answer..

Resources