<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Code Train &#187; keyboard control</title>
	<atom:link href="http://thecodetrain.co.uk/tag/keyboard-control/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecodetrain.co.uk</link>
	<description>Where Neil Crosby talks about coding on the train...</description>
	<lastBuildDate>Sun, 03 Apr 2011 18:15:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Controlling iTunes across multiple computers with the keyboard</title>
		<link>http://thecodetrain.co.uk/2009/10/controlling-itunes-across-multiple-computers-with-the-keyboard/</link>
		<comments>http://thecodetrain.co.uk/2009/10/controlling-itunes-across-multiple-computers-with-the-keyboard/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 12:32:56 +0000</pubDate>
		<dc:creator>Neil Crosby</dc:creator>
				<category><![CDATA[Blog Posts]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[keyboard control]]></category>
		<category><![CDATA[scratching an itch]]></category>

		<guid isPermaLink="false">http://thecodetrain.co.uk/?p=312</guid>
		<description><![CDATA[<p>Over the last few days on Twitter I&#8217;ve been talking about my peculiar iTunes setup, and a few people have been asking me if I&#8217;ll blog about it.  So, here goes&#8230;</p>

<p>My situation is that my iTunes music library is stored on my MacMini that lives in my living room (connected to and powering my TV experience). However, most of the time I spend using my MacBook Pro, which spends most of its time in the office upstairs a fair way away from the MacMini. Because I spend most of my time at the laptop, it&#8217;s nice to have music available for me to listen to on it.  Of course, if I just wanted to <em>listen</em> to music then this would be a very short blog post &#8211; I could use iTunes to share the library from the MacMini and listen to the music upstairs, or I could use Spotify or Last.fm. The problem with these as solutions are that I make heavy use of Smart and Genius Playlists in iTunes to generate playlists of music to listen to. Using iTunes&#8217; sharing feature doesn&#8217;t allow me to rate tracks in the originating library (even with iTunes 9&#8242;s &#8220;Home Sharing&#8221; feature), and it also doesn&#8217;t generate extra playcount in the originating library for the things I listen to. This means my Smart Playlists don&#8217;t update in the expected way, and I become a sad panda. Likewise, Genius Playlists don&#8217;t work in a usable way when using a shared library, so this doesn&#8217;t really work for me.</p>

<p>What I wanted was a way to play my music using the MacMini downstairs, but have the music erupt from the speakers connected to my MacBook Pro.  As it turns out, there&#8217;s an app for that &#8211; <a href="http://www.rogueamoeba.com/airfoil/mac/">Airfoil</a>. This lovely application hijacks audio from one device and sends it out across the network to multiple other devices of your choice, all in sync. So, immediately I was able to use OSX&#8217;s Screen Sharing app to connect to my MacMini, start some music playing in iTunes and then have Airfoil pipe it out to my MacBook Pro.  It was a solution that was sheer elegance in its simplicity. Yes, you have to wait a second or so after pressing play before you hear anything come out of your speakers, but that&#8217;s down to Airfoil making sure all your devices are in sync before it starts to do anything.  All in all, it&#8217;s brilliant. It costs $25, but that&#8217;s a small price to pay for this functionality for me.</p>

<p>The only problem is that in playing music on a different computer than the one you&#8217;re on, you&#8217;re playing music on a different computer than the one you&#8217;re on.  So various things, like media keys on your keyboard don&#8217;t work in the way you expect. So, whenever I was wanting to do simple things like pause my music I was having to go into Apple&#8217;s Screen Sharing app, log into the MacMini and then press the pause button in iTunes.  Not ideal.  So, I wrote a quick AppleScript in Apple&#8217;s Script Editor:</p>

<pre><code>tell application "iTunes" of machine "eppc://macmini-2.local" to playpause
</code></pre>

<p>Yup, that&#8217;s a really simple AppleScript.  Something I wasn&#8217;t aware of until a couple of days ago is that it&#8217;s possible to run AppleScript that runs AppleScript on a different machine.  All you have to do is go into <code>System Preferences</code>, open the <code>Sharing</code> panel, and enable <code>Remote Apple Events</code>. The first time you try to run an event on the remote machine you&#8217;ll be asked to enter your credentials on the local machine, which you can save to your keychain for auto-use in the future.  Now, if I run that AppleScript then iTunes on the remote machine will toggle its play state, and consequently on my local machine.  Awesome.</p>

<p>It&#8217;s just as easy to write other scripts as well. For example, to advance to the next track, just change <code>playpause</code> to <code>play (next track)</code>.</p>

<p>But we&#8217;re still not controlling iTunes on the remote machine with just a keypress.  If you&#8217;ve got something like Quicksilver installed on your machine then you should be able to simply hook the script up to a key combination of your choice. I don&#8217;t currently have Quicksilver installed on this machine (and wasn&#8217;t about to install it just for this), so I had to find another alternative. What I&#8217;m currently using is <a href="http://www.red-sweater.com/fastscripts/">FastScripts Lite</a>, a free app that adds an icon to your menubar that contains menu items for any AppleScripts you put in a certain directory. The nice thing about FastScripts is that it also allows you to enter a keypress combo for any of these scripts by going into its <code>Preferences</code> pane and double clicking on the Shortcut field next to the relevant script. I&#8217;ve got <code>playpause</code> bound to <code>ctrl-up</code>, <code>next track</code> to <code>ctrl-right</code> and <code>previous track</code> to (you guessed it) <code>ctrl-left</code>. Now I can easily change what I&#8217;m listening to with a quick keypress, and I&#8217;m happy.</p>

<p>Well, I&#8217;m almost happy.  I still need to have Screen Sharing open so that I can see what&#8217;s actually in the playlist that I&#8217;m listening to.  There&#8217;s a solution to that as well though.  All I needed do was create a script that calls some AppleScript on the MacMini, grabs the current playlist info and then outputs it into a web page. I could then use this page as the basis of a Dashboard widget and I&#8217;d only ever have to press F12 to see my current playlist.  And that&#8217;s what I did. To find out how I did it though, you&#8217;ll have to read the <a href="http://thecodetrain.co.uk/2009/11/displaying-your-current-remote-itunes-playlist-on-your-local-macs-dashboard/">next post</a>!</p>
<div style="display:block"><small><em><a href="http://neilcrosby.com">Neil Crosby</a> also blogs at about t-shirts at <a href="http://iwearcotton.com">I Wear Cotton</a>, writes <a href="http://thetenwordreview.com/users/workingwithme">Ten Word Reviews</a>, and uploads <a href="http://www.flickr.com/photos/thevoicewithin/">photos</a> to flickr.  You can follow a combined feed of posts at <a href="http://neilcrosby.com/">NeilCrosby.com</a>.</em></small></div>]]></description>
			<content:encoded><![CDATA[<p>Over the last few days on Twitter I&#8217;ve been talking about my peculiar iTunes setup, and a few people have been asking me if I&#8217;ll blog about it.  So, here goes&#8230;</p>

<p>My situation is that my iTunes music library is stored on my MacMini that lives in my living room (connected to and powering my TV experience). However, most of the time I spend using my MacBook Pro, which spends most of its time in the office upstairs a fair way away from the MacMini. Because I spend most of my time at the laptop, it&#8217;s nice to have music available for me to listen to on it.  Of course, if I just wanted to <em>listen</em> to music then this would be a very short blog post &#8211; I could use iTunes to share the library from the MacMini and listen to the music upstairs, or I could use Spotify or Last.fm. The problem with these as solutions are that I make heavy use of Smart and Genius Playlists in iTunes to generate playlists of music to listen to. Using iTunes&#8217; sharing feature doesn&#8217;t allow me to rate tracks in the originating library (even with iTunes 9&#8242;s &#8220;Home Sharing&#8221; feature), and it also doesn&#8217;t generate extra playcount in the originating library for the things I listen to. This means my Smart Playlists don&#8217;t update in the expected way, and I become a sad panda. Likewise, Genius Playlists don&#8217;t work in a usable way when using a shared library, so this doesn&#8217;t really work for me.</p>

<p>What I wanted was a way to play my music using the MacMini downstairs, but have the music erupt from the speakers connected to my MacBook Pro.  As it turns out, there&#8217;s an app for that &#8211; <a href="http://www.rogueamoeba.com/airfoil/mac/">Airfoil</a>. This lovely application hijacks audio from one device and sends it out across the network to multiple other devices of your choice, all in sync. So, immediately I was able to use OSX&#8217;s Screen Sharing app to connect to my MacMini, start some music playing in iTunes and then have Airfoil pipe it out to my MacBook Pro.  It was a solution that was sheer elegance in its simplicity. Yes, you have to wait a second or so after pressing play before you hear anything come out of your speakers, but that&#8217;s down to Airfoil making sure all your devices are in sync before it starts to do anything.  All in all, it&#8217;s brilliant. It costs $25, but that&#8217;s a small price to pay for this functionality for me.</p>

<p>The only problem is that in playing music on a different computer than the one you&#8217;re on, you&#8217;re playing music on a different computer than the one you&#8217;re on.  So various things, like media keys on your keyboard don&#8217;t work in the way you expect. So, whenever I was wanting to do simple things like pause my music I was having to go into Apple&#8217;s Screen Sharing app, log into the MacMini and then press the pause button in iTunes.  Not ideal.  So, I wrote a quick AppleScript in Apple&#8217;s Script Editor:</p>

<pre><code>tell application "iTunes" of machine "eppc://macmini-2.local" to playpause
</code></pre>

<p>Yup, that&#8217;s a really simple AppleScript.  Something I wasn&#8217;t aware of until a couple of days ago is that it&#8217;s possible to run AppleScript that runs AppleScript on a different machine.  All you have to do is go into <code>System Preferences</code>, open the <code>Sharing</code> panel, and enable <code>Remote Apple Events</code>. The first time you try to run an event on the remote machine you&#8217;ll be asked to enter your credentials on the local machine, which you can save to your keychain for auto-use in the future.  Now, if I run that AppleScript then iTunes on the remote machine will toggle its play state, and consequently on my local machine.  Awesome.</p>

<p>It&#8217;s just as easy to write other scripts as well. For example, to advance to the next track, just change <code>playpause</code> to <code>play (next track)</code>.</p>

<p>But we&#8217;re still not controlling iTunes on the remote machine with just a keypress.  If you&#8217;ve got something like Quicksilver installed on your machine then you should be able to simply hook the script up to a key combination of your choice. I don&#8217;t currently have Quicksilver installed on this machine (and wasn&#8217;t about to install it just for this), so I had to find another alternative. What I&#8217;m currently using is <a href="http://www.red-sweater.com/fastscripts/">FastScripts Lite</a>, a free app that adds an icon to your menubar that contains menu items for any AppleScripts you put in a certain directory. The nice thing about FastScripts is that it also allows you to enter a keypress combo for any of these scripts by going into its <code>Preferences</code> pane and double clicking on the Shortcut field next to the relevant script. I&#8217;ve got <code>playpause</code> bound to <code>ctrl-up</code>, <code>next track</code> to <code>ctrl-right</code> and <code>previous track</code> to (you guessed it) <code>ctrl-left</code>. Now I can easily change what I&#8217;m listening to with a quick keypress, and I&#8217;m happy.</p>

<p>Well, I&#8217;m almost happy.  I still need to have Screen Sharing open so that I can see what&#8217;s actually in the playlist that I&#8217;m listening to.  There&#8217;s a solution to that as well though.  All I needed do was create a script that calls some AppleScript on the MacMini, grabs the current playlist info and then outputs it into a web page. I could then use this page as the basis of a Dashboard widget and I&#8217;d only ever have to press F12 to see my current playlist.  And that&#8217;s what I did. To find out how I did it though, you&#8217;ll have to read the <a href="http://thecodetrain.co.uk/2009/11/displaying-your-current-remote-itunes-playlist-on-your-local-macs-dashboard/">next post</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://thecodetrain.co.uk/2009/10/controlling-itunes-across-multiple-computers-with-the-keyboard/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

