Controlling VLC through the LAN
When I watch movies on my TiBook, I like to stream them from the QuickSilver (the TiBook runs much hotter playing a DVD than playing a stream). I use VLC on both machines to do it, and it works fine. But the problem with this approach is that you cannot control VLC on the server from the client (and if you pause the movie from the client, it will continue to play on the server).
Since VLC is scriptable, the obvious way to work around this limitation is to enable and use Remote Apple Events. Enabling this service from the Sharing prefs pane (1) allows to run AppleEvents across the LAN, so in theory all I should have to do in order to toggle VLC on the server between play and pause is to run on the client an AppleScript that goes:
Tell application "VLC" of machine "eppc://10.0.1.2" to play
Unfortunately, VLC (0.8.2) appears to have a bug that prevents it to receive remote AppleEvents (the error returned is something like "The application "VLC" is not running on this machine").
But since VLC works fine when it receives events that come from the machine it's running on, I worked around the problem by writing a little AppleScript application that runs on the server and redirects to VLC the commands it receives as remote AppleEvents. Here's the script:
on relay(thisCommand) tell application "VLC" if thisCommand = "play" then play else if thisCommand = "stop" then stop else if thisCommand = "next" then next else if thisCommand = "prev" then previous end if end tell end relay
I saved this script as Application, with the "Stay Open" option checked, and put it (on the server) at ~/Library/Scripts/Applications/VLC/VLCRemoteController, so it appears in the Script menu (2) when VLC is frontmost and I can launch it from there.
Then on the client I created four oneliner scripts, that go:
tell application "VLCRemoteController" of machine "eppc://10.0.1.2" to relay("play")(saved as ~/Library/Scripts/Applications/VLC/Play-Pause)
tell application "VLCRemoteController" of machine "eppc://10.0.1.2" to relay("stop")(saved as ~/Library/Scripts/Applications/VLC/Stop)
tell application "VLCRemoteController" of machine "eppc://10.0.1.2" to relay("next")(saved as ~/Library/Scripts/Applications/VLC/Next)
tell application "VLCRemoteController" of machine "eppc://10.0.1.2" to relay("prev")(saved as ~/Library/Scripts/Application/VLC/Previous)
That's it: now I have the items "Play-Pause", "Stop", "Next" and "Previous" in the Script menu when VLC is frontmost on the client, and if the VLCRemoteController application is running on the server, I can use these commands to control it.
Pretty cool, uh? And easy, too. Took me longer to write this. :)
(1) To enable remote AppleEvents (to do on both the server and the client):
- Launch System Preferences and click on Sharing
- In the Services tab, check the checkbox in front of Remote Apple Events.
- That's it (if the firewall is enabled, the port 3031 will automatically be opened).
(2) The Script menu can be enabled in Panther by double-clicking on /Applications/AppleScript/Script Menu, and in Tiger from /Applications/AppleScript/AppleScript Utility.