Workaround for the "Could not find Library" Problem with the iPhone Remote App

# Filed on Aug 16, 2008 by AnthonyDiSante 9 replies

The Remote app for the iPhone is an amazing thing: it turns your iPhone into a remote control for iTunes on your PC -- which is to say, a remote control for your stereo.  But unlike the infrared remote that came with your stereo, this remote works over wifi, so while you’re out on the porch grilling up some steaks, you can take your iPhone out of your pocket and use it to play some music on the stereo inside.

But I’m having a serious problem with Remote that I can’t find much information about online: Remote connects to iTunes and works fine for a while, but then it suddenly fails to connect to iTunes, and cannot connect again until you go to the computer and close & re-open iTunes.  My computer is a Mac mini PPC G4, but from posts in the Apple forums I know that some Windows users are having this problem too.

I had been running OS X Tiger 10.4.11; I upgraded to Leopard -- first 10.5.1 then 10.5.4 -- but that didn’t fix the problem.  I rebooted the iPhone.  I uninstalled the Remote app and reinstalled it.  I tried another iPhone.  I turned off the OS X firewall.  I made sure OS X wasn’t going to sleep.  I upgraded to iPhone OS 2.0.1.  None of those things fixed the problem.

But I discovered that if I disabled & re-enabled my Mac’s network connection, that did fix the problem.  So I immediately set to work creating a way to make this happen from the iPhone, since having to actually go over to the computer defeats the purpose of having a remote.  The result is a 2-tap solution that lets you reset your Mac’s network connection from your iPhone.  Here’s how.


Note: in the following instructions, replace "username" with your own username.

Step 1 of 6: Start Apache & Enable Your Sites Folder

In your Mac’s system prefs, go to Sharing, then enable Web Sharing.  Then run this command:

sudo cp /etc/httpd/users/username.conf /etc/apache2/users/

Go into your /Users/username/Sites/ folder and create a new subfolder called "cgi-bin".  Then edit the file /etc/apache2/users/username.conf and add the following line to the end of it:

ScriptAlias /~username/cgi-bin/ "/Users/username/Sites/cgi-bin/"

Now disable & re-enable Web Sharing, or run the command "sudo apachectl restart" which does the same thing.


Step 2 of 6: Create & Name Your Network Profiles


In your Mac’s system prefs, go to Network, then name your default network location "Online", and then create a second location called "Offline" which has all the adapters disabled.

And if your Mac doesn’t already have a fixed/static IP address, then give it one (in your "Online" location).  If your automatic/dynamic IP was something like 192.168.1.100, then set its fixed IP to 192.168.1.200.


Step 3 of 6: Create CGI Script


Create the file /Users/username/Sites/cgi-bin/fix_itunes_remote.cgi and put the following into it:

#!/usr/bin/perl
exit unless $ENV{REMOTE_ADDR} =~ /^192\.168\./;
my $sentinel = "/Users/username/Public/Drop Box/fix_itunes_remote";
`touch "$sentinel"`;
`chmod a+rw "$sentinel"`;
print "Content-type: text/html\n\n";
print qq`<html>`;
print qq`<body onload="javascript:window.opener='x';window.close();">`;
print qq`</body></html>\n`;

Then run this command to make that file executable:

chmod a+x /Users/username/Sites/cgi-bin/fix_itunes_remote.cgi

Step 4 of 6: Create Shell Script


Create the file /Users/username/togglenet.sh and put the following into it:

#!/bin/bash
SENTINEL="/Users/username/Public/Drop Box/fix_itunes_remote"
for ((i=1; i<=9; i++))
do
  if [ -e "$SENTINEL" ]
  then
    echo "sentinel exists; fixing itunes remote now."
    rm -rf "$SENTINEL"
    /usr/sbin/scselect Offline
    sleep 5
    /usr/sbin/scselect Online
  else
    sleep 5
  fi
done

Then run this command to make that file executable:

chmod a+x /Users/username/togglenet.sh

Step 5 of 6: Schedule Shell Script To Run Regularly


Run the command "crontab -e" and put the following into it:

*/1 * * * * /Users/username/togglenet.sh

Step 6 of 6: Use Your iPhone to Run the Script


On your iPhone, open Safari and visit this URL to reset your Mac’s network connection:

http://192.168.1.200/~username/cgi-bin/fix_itunes_remote.cgi

...where 192.168.1.200 is the IP address of your Mac.  Note that the page will automatically close itself.

Create a bookmark for this page on your iPhone’s home screen, right next to your existing Remote app, and name the bookmark FixRemote.  That way you can just tap FixRemote and then Remote and you’re in business.

That’s It

Visiting that URL causes the CGI script to create the sentinel file; when the shell script sees the sentinel file, it resets your Mac’s network connection.

The cronjob runs the shell script once per minute, all day every day.  And the shell script sleeps for a few seconds then loops and runs again, so the frequency of checking is actually every few seconds, not just once per minute.  If it finds the sentinel file, it turns off the network and then turns it back on again, by using the scselect command to temporarily switch your network to its "Offline" profile.

Comments:

01. Sep 14, 2008 at 10:28am by broct:

Apple posted this fix

http://support.apple.com/kb/TS1741

Worked without the hassle above.

02. Sep 14, 2008 at 12:04pm by AnthonyDiSante:

I actually did see that troubleshooting page (not exactly a "fix" in the sense of a bugfix) and I tried everything on it; it did not solve the problem for me.

03. Nov 6, 2008 at 09:01pm by Ender:

Doh! I’ve been connected to a neighbors WiFi all this time. :)

04. Apr 1, 2009 at 09:20am by Dodger:

Why not just doo all the sentinel and restarting connection stuff in the Perl script?

05. Apr 2, 2009 at 09:26am by AnthonyDiSante:

Because Apache might not have permission to change the networking profile, but the logged-in user (which executes cron and BASH) does.

06. Jul 19, 2009 at 02:58pm by Jason:

I love the comment from ’broct’ above.  It appears he either didn’t read your post, or didn’t read the apple support page before he suggested it, otherwise he’d easily see that you listed trying everything that Apple said to do, in that very help page.  What a dozer....

Anyway, any clue how I can do something similar in Windows Vista?  This "Can’t find library" issue is driving me insane.

07. Jul 19, 2009 at 03:02pm by Jason:

OH, BTW - I just did a manual network disconnect/reconnect from my wireless in Windows Vista, and literally, without touching another thing, in less than 5 seconds, the "remote" app connected to the library, perfectly. 

So... it’s the same issue you had, as I had the same problem, and the same solution worked for me, eventhough we’re on different platforms.  What’s going on for us, that apparently other people aren’t experiencing?  And again... what can I do in Windows that would work like what you’ve done for your mac?

08. Jul 19, 2009 at 09:54pm by AnthonyDiSante:

About a month after I created this post, I tracked the problem down to a router issue.  Replacing my router fixed the problem.  Sorry for not updating this post sooner.  I created this thread on the Apple Forums which contains more details, but basically my router was briefly dropping my connection at regular intervals, which apparently caused issues with iTunes+RemoteApp, although other aspects of iTunes (podcasts updates, etc) had no trouble with it.

Unfortunately I’m not sure if something similar to my workaround here would work on Vista; I guess it would depend on whether there are command-line tools for toggling the network connection in Vista.

09. Feb 11, 2010 at 12:05pm by delboy:

Using mac 10.6.2 with snow leopard, after weeks of trying various things with iphone remote, sometimes connects right away other times it cannot find library.I now turn off wi-fi on phone, attempt to connect through remote, says it cant connect as not connected to wi-fi, turn on wi-fi then try remote again and it usually connects ok Dont know why

Reply to this message here:

Your name
Email (why?)
Website (if you have one)
Subject
search posts:

home | archives ]