Author |
|
nadler Super User
Joined: February 25 2006 Location: United States
Online Status: Offline Posts: 354
|
Posted: July 08 2006 at 17:38 | IP Logged
|
|
|
I'm trying to control itunes from PH and have stumbled across various methods of doing so. The latest, and the most promising if it works, is using some free VB scripts. The script I am trying out mutes itunes. The one I ultimately want to work is one that starts itunes with a particular playlist playing.
When I double click on the Mute.vbs file from its directory it works well, so I know it works. I've tried launching it as an application in PH and that doesn't work. I've also tried using the function ph_runscript_0 but that gives me a -4 error. I'm assuming I have the wrong syntax or it just can't be done.
ph_runscript_0("C:\Program Files\iTunes\Scripts\Mute.vbs","vbscript",0,0,"[I don't know what should go here]")
Any suggestions?
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: July 09 2006 at 09:57 | IP Logged
|
|
|
Check out the first post in this thread. The last parameter is the routine in the script to execute.
Maybe the last post on this page applies?
Edited by TonyNo - July 09 2006 at 09:57
|
Back to Top |
|
|
nadler Super User
Joined: February 25 2006 Location: United States
Online Status: Offline Posts: 354
|
Posted: July 09 2006 at 15:47 | IP Logged
|
|
|
Thanks for the suggestion. I'm not able to get it to work though. I'm wondering if this is not a true vb script as I had to install a small program "Script for itunes" first. Maybe Dave can take a look if he gets a chance. The error I get is "Error 24 Object required 'WScript."
Here is the script:
Dim iTunes
Dim ArgStr
Dim Msg
' Create app object
Set iTunes = WScript.CreateObject("iTunes.Application")
' Get the argument
Select Case Wscript.Arguments.Count
Case 0
ArgStr = ""
Case 1
ArgStr = Lcase(Trim(Wscript.Arguments.Item(0)))
Case Else
ArgStr = "error!"
End Select
' Now interpret the argument and act accordingly
Select Case ArgStr
Case "on"
iTunes.Mute = True
Case "off"
iTunes.Mute = False
Case ""
' Toggle
iTunes.Mute = Not (iTunes.Mute)
Case Else
Msg = "Please specify 'Mute on' or 'Mute off' to set the mute state, or 'Mute'"
Msg = Msg + " (without an argument) to toggle the mute state."
Wscript.Echo Msg
End Select
' Done; release object
set iTunes = nothing
rem End of script.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: July 10 2006 at 23:25 | IP Logged
|
|
|
Noel,
Ok, I took a look at the script and made the proper adjustments so that it will work within PowerHome. The script as you posted it was designed to be executed from the commandline which is a little different than what the Windows Script Host object that PowerHome uses is expecting. Below is the corrected script:
Code:
sub main(arg)
Dim iTunes
Dim ArgStr
Dim Msg
' Create app object
Set iTunes = CreateObject("iTunes.Application")
' Get the argument
argstr = lcase(trim(arg))
' Now interpret the argument and act accordingly
Select Case ArgStr
Case "on"
iTunes.Mute = True
Case "off"
iTunes.Mute = False
Case ""
' Toggle
iTunes.Mute = Not (iTunes.Mute)
Case Else
Msg = "Please specify 'Mute on' or 'Mute off' to set the mute state, or 'Mute'"
Msg = Msg + " (without an argument) to toggle the mute state."
Echo Msg
End Select
' Done; release object
set iTunes = nothing
msgbox "done"
rem End of script.
end sub
|
|
|
As you can see, the major changes include surrounding the script within the confines of a subroutine or function (in this case, the "main" subroutine). This allows you to embed multiple scripts within a single file as multiple functions and subroutines. The other major change is the dropping of the "Wscript." object as it does not exist in this context. The last major difference is the removal of the commandline arguments reference. Since the script is not run from a commandline, this construct does not exist. However, we do have the ability to pass arguments to the function or subroutine so you can see the minor changes that have been made.
To execute this from within PowerHome, just use the ph_runscript_1 function (use the _1 function because you're passing 1 parameter) with the following arguments:
ph_runscript_1(("C:\Program Files\iTunes\Scripts\Mute.vbs","vbscript",0,0,"main","on")
This should take care of it for you.
Dave.
|
Back to Top |
|
|
nadler Super User
Joined: February 25 2006 Location: United States
Online Status: Offline Posts: 354
|
Posted: July 11 2006 at 06:54 | IP Logged
|
|
|
That's terrific. Thanks!
|
Back to Top |
|
|
nadler Super User
Joined: February 25 2006 Location: United States
Online Status: Offline Posts: 354
|
Posted: July 11 2006 at 10:00 | IP Logged
|
|
|
Following Dave's lead I was able to change the VBscript PlayPlaylist.vbs to a vbscript that would run in PH. Itunes does not allow you to play a particular playlist or a particular song when it is opened. There are no startup switches for itunes that do this. This vbscript allows you to chose a playlist when you open itunes or at any other time. If anyone is interested in a vbscript to play a particular song in itunes, let me know and I will post that as well.
In case anyone is interested in how I use this...I have some keypadlincs V2 throughout the house. On each is a MUSIC button. When you press the MUSIC button it turns on that room's speakers and then cycles through 5 music channels and then off. I wanted each music channel to be a specific type of music (Classic, Jazz, Rock, Local News, NPR). The first time the MUSIC button is pressed each day the speakers for the room are turned on and I have TSS instructions how to use the button. Thereafter, each time the button is pressed (either on or off - I have a trigger for both) the button cycles through 5 different channels of music. The sixth press of the button turns the speakers off in the room. Itunes allows me to not only have mp3 music channels but also several online radio stations. This is a good mix for me.
I don't have a multiple amp setup so it's the same music or news in all rooms used and if someone in one room changes the music, it changes it in all the rooms. But, it's all set up to use a RUssound or similar multi channel amp if I ever decide to get one.
The caveat to the script is that I really am not conversant in VB and just followed Dave's lead (but it does work). Here's the script:
rem Main script:
sub main(arg)
' Variables
Dim iTunes 'As iTunes
Dim ArgPlaylist 'As String
Dim ArgPlaylistLcase 'As String
Dim Playlist 'As IITPlaylist
Dim TempPlaylist 'As IITPlaylist
Dim SyntaxErr 'As Boolean
Dim Msg 'As String
Dim ArgStr
' Init
Set Playlist = Nothing
' Connect to iTunes app
Set iTunes = CreateObject("iTunes.Application")
' Find the specified playlist
Set Playlist = Nothing
ArgPlaylistLcase = LCase(Arg)
For Each TempPlaylist In iTunes.LibrarySource.Playlists
If LCase(TempPlaylist.Name) = ArgPlaylistLcase Then
' Match!
Set Playlist = TempPlaylist
Exit For
End If
Next 'TempPlaylist
' Did we find one?
If Playlist Is Nothing Then
echo "The playlist """ + ArgPlaylist + """ could not be found."
Quit
Else
' Start playing the playlist
Playlist.PlayFirstTrack
End If
' Done; clean up
Set Playlist = Nothing
Set iTunes = Nothing
Rem End of script.
end sub
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: July 14 2006 at 16:27 | IP Logged
|
|
|
Noel,
Looking good . Glad to see it's working for you and appreciate you posting the code for others to use as well.
Dave.
|
Back to Top |
|
|
jbbtex Senior Member
Joined: February 15 2007 Location: United States
Online Status: Offline Posts: 181
|
Posted: September 28 2010 at 21:05 | IP Logged
|
|
|
nadler,
I just started using the same scripts and they are all
working fine.
However, I'd like to know the current iTunes play state.
This script is supposed do just that but I have no idea
how to how to get them into PH.
Are you using it and would you share how?
Code:
rem This script immediately exits, setting the
ERRORLEVEL value to
rem indicate the current play state of iTunes.
rem Possible return values:
rem 0 = Stopped
rem 1 = Playing
rem 2 = Fast-forwarding
rem 3 = Rewinding
rem Copyright 2004 Maximized Software, Inc. All rights
reserved.
rem More info is available at:
http://www.maximized.com/freeware/ScriptsForiTunes/
rem Version 2004-12-09-1
' Variables
dim iTunes, CurState
' Connect to iTunes app
set iTunes = CreateObject("iTunes.Application")
' Get current state
CurState = iTunes.PlayerState
' Done; release object
set iTunes = nothing
' Quit, returning state
Wscript.Quit CurState
rem End of script. |
|
|
__________________ Brady
"Never tell people how to do things. Tell them what to do and they will surprise you with their ingenuity." - Gen. George S. Patton
|
Back to Top |
|
|
nadler Super User
Joined: February 25 2006 Location: United States
Online Status: Offline Posts: 354
|
Posted: September 29 2010 at 15:48 | IP Logged
|
|
|
When I switched to windows 7 I dropped then script. Most of my
music is now played through my receiver which gives similar info when
I play Internet and HD radio. But, as I recall I ran a background app
in xp which wrote the title of the song to a file. Using PH's file plugin
every time the filemupdated PH read it and brought it into PH as a
global variable. It also reported at least the stop,play,pause status. I
don't recall the name of that app however and it didn't work in win7.
Not much help. Sorry.
|
Back to Top |
|
|