Home Link

Hello, my name is Brett Terpstra, and it’s nice to meet you. Elegant solutions to complex problems. Curious?

homecontrolheaderimage

HomeControl: Local Mac control for iPhone

HomeControl: Local Mac control for iPhone Tagged:
Oct 02, 2010 (592 days ago)

I tried out a tip recently for controlling a Mac via Mobile Safari on your iPhone, and it got me thinking, which is often dangerous. I put together this little web app today as a proof of concept (that got a little out of hand). It basically provides a full interface for volume control, application starting and stopping and many iTunes functions, including volume and EQ. All features provide interface feedback and update you with current info from your Mac.

Video preview

httpv://www.youtube.com/watch?v=KTcISVU4Nf4

YouTube Link…

Setting up your web server

To run it, you need to run your local web server as your own user. This is, of course, a major security risk and completely inadvisable if your local web server is open to outsiders in any way. Mine’s not, so I didn’t put too much time into figuring out a more secure way to do this. If you have any clues in that area, let me know and I’ll post them.

To run your local web server as a different user, you need to edit /etc/apache2/httpd.conf. You’ll need to edit it as root, so use sudo to launch your text editor of choice (e.g. sudo vi /etc/apache2/httpd.conf). If you, like me, just use TextMate’s mate command, you’ll be prompted for a password when you save.

Locate the lines:

User _www
Group _www

Change them to:

User yourusername
Group staff

You’ll also need to enable PHP, if you haven’t already. If you haven’t, locate the line that starts with:

#LoadModule php5_module

Just remove the hashmark at the beginning (#) to turn PHP on.

Now, at the command line, type sudo apachectl graceful to restart the server under the new user. If everything is in place, you’ll be able to run HomeControl without a hitch now. Turn on Web Sharing in System Preferences > Sharing to keep the web server running through reboots and logouts.

Installing HomeControl

Just download the zip file at the end of this post and unzip it into your ~/Sites folder. If you prefer to have it elsewhere, or have a custom folder set up for Apache, it will run just fine in any folder, as long as you can access it from a web browser on the local network.

Next, point your web browser to the folder. If you put the ‘homecontrol’ folder directly in ~/Sites, you should be able to reach it at the url http://computer_name.local/~Username/homecontrol. You need to know the name of the computer it’s on (set in System Preferences > Sharing, at the top), and your username on that system, substituting each in the appropriate place in the url.

Once you’ve loaded the page and tested it out, use the “+” icon at the bottom of Mobile Safari’s web browser to add an icon to your home screen which will take you directly there in the future, and will run the app full-screen.

Customizing HomeControl

Since I know not everybody who wants to try this out is going to be ready to hack into the jQuery and PHP, I made quite a few bits of the app modifiable with simple HTML edits. If you’re comfortable with that, you can change the list of applications and add iTunes features quite easily.

Application launcher

  • Locate the div with the id “apps”
  • Find the unordered list (<ul>) inside of it
  • Edit or copy and edit existing lines by changing only the name of the application in the first span
  • Use the exact displayed name of the application you want to control, and HomeControl will pass it to the PHP exec function

iTunes functions

  • Locate the div with the id “itunes”
  • Find the unordered list inside of it with the id “itunescmd”
  • Add new features by copying an existing line and changing the rel attribute and the text of the link
    • The rel attribute passes the actual iTunes AppleScript command, which will be appended to a ‘tell application "iTunes" to’ line and passed to osascript
    • The text of the link is the title which will appear in the menu

iTunes EQ Presets

  • Locate the div with the id “ituneseq”
  • Find the unordered list inside of it
  • Edit the text of the links in the list with the exact title of the preset you want to control
  • Add or remove list items as desired

Startup screen and icon

  • Edit homecontrolicon.png in the homecontrol folder to customize the app’s icon on the homescreen.
  • Edit hc_startup.png in the homecontrol folder to customize the startup screen.
  • If you’ve installed the web app, delete the icon and reinstall from Mobile Safari to see the new images.

Advanced customization

If you’re handy with the jQuery, the PHP and the HTML, you can do a lot with the examples in the code. It’s very much a proof-of-concept, and intended to be a jumping point for more experimentation, so have at it.

The app currently uses the jQTouch library, but mostly for the CSS. It has very few dependencies on the API, so it should be a relatively trivial matter to switch to a different library. It does rely quite heavily on jQuery, though.

The main PHP/osascript calls are in functions.php. All functions are called using jQuery’s $.get function, which makes Ajax calls to the functions.php file in the background and receives updates on completion.

Have fun, hopefully my horrible waste of time will be someone else’s inspiration…

Screenshot of HomeControl Main Screen

Main Screen

Screenshot of HomeControl Applications Screen

Applications Screen

Screenshot of HomeControl iTunes controls

iTunes controls

Download

download image for HomeControl
Download

HomeControl — A web app—designed to run on a local server and be accessed over the local network—which provides control over volume, iTunes features and application launching. This is a skeleton for further experimentation. More Info

If you like any (or all) of my projects, please consider a small PayPal donation to my coffee fund!

41 Responses to “HomeControl: Local Mac control for iPhone”

  1. Wow! You turned my silly little script into a highly functioning application. Cool

  2. Anville says:

    Wow, this looks very cool! I have just been on a parallel path the last week or so, actually, and came up with this : http://​code​.google​.com/​p​/​b​u​t​t​o​n​b​o​a​rd/

    Your web development skills are much better then mine, I see :-)

    I also started off with PHP and apache, but moved over to using Python and the Tornado web server package (http://​www​.tornadoweb​.org/). Using Platypus ( http://​www​.sveinbjorn​.org/​p​l​a​t​y​pus), I was able to make a user launchable web-server app with custom password and port.

    Can’t wait to look at your stuff this evening!

    • Brett says:

      That’s actually a really awesome solution to the web server security issue. Looking forward to digging into your code, too!

  3. […] HomeControl: Local Mac control for iPhone [Brett Terpstra] Tagged:itunesmacremote controlvideo […]

  4. […] There’s no end to the ways you can remote control your Mac from your iPhone, and Brett Terpstra shows you how to do so with HomeControl, a local Mac controller for iPhone. […]

  5. John Watson says:

    It looks like you may be missing a few images from the zip file. I’m getting a few 404’s while things are running. I’m adding support for toggling Airfoil speakers. Let me know if you’re interested in my (very hacky) code!

  6. […] detailed overview explains how you can edit all sorts of options by just editing a little HTML. To give you an idea, […]

  7. […] detailed overview explains how you can edit all sorts of options by just editing a little HTML. To give you an idea, […]

  8. […] detailed overview explains how you can edit all sorts of options by just editing a little HTML. To give you an idea, […]

  9. […] detailed overview explains how you can edit all sorts of options by just editing a little HTML. To give you an idea, […]

  10. […] detailed overview explains how you can edit all sorts of options by just editing a little HTML. To give you an idea, […]

  11. […] Follow this link: HomeControl:iPhone «して、Brett TerpstraさんのローカルMacのコントロール […]

  12. Hunter says:

    I’m getting all sorts of errors when I try to use it. Everything shows up, but when I push buttons, I get script errors at the top of the screen and nothing happens. What have I done wrong?

  13. zen says:

    hi guys, is it possible to control the “apple’s special keys” (like volume +/- or brightness +/-) with this app? i haven’t found any program that can actually do this :(

  14. […] detailed overview explains how you can edit all sorts of options by just editing a little HTML. To give you an idea, […]

  15. Jeff says:

    I cannot seem to get the web app working. Every time a function is called, I get errors regarding a parameter needing to be a resource, but given as a boolean. This is true of the volume commands and app launching commands. The iTunes commands don’t seem to do much of anything. I have my personal web server up and running with PHP5 installed. Any ideas?

    • Brett says:

      Are you running the stock Snow Leopard PHP5, or a custom build? I’ll email you directly and see if I can get a screenshot of the error message so I’m sure I know what you’re seeing.

  16. Hunter says:

    I’m getting the same thing as Jeff!

    • Brett says:

      I just got a screenshot from Jeff, and it appears to be a permissions problem with writing the volume out to a text file, at least in part. In Terminal, change to the folder where homecontrol lives (cd ~/Sites/homecontrol) and then type

      touch volume.txt; chmod 777 volume.txt

      See if that helps, and let me know.

      • Hunter says:

        Still doesn’t work. Every time I use “volume up” it says volume 10 no matter how many times; volume down yields –10 every time. mute doesn’t seem to do anything. itunes still doesn’t respond to anything. no more error messages though!

  17. max says:

    Hi, I installed the homecontrol scripts on my webserver and the page loads fine. the first time I went to the application section it figured out that sendtome was started but did not recognize itunes running. since then it does not recognise any app being launched . whenever i turn any app on, it says “error loading itunes” on the info bar.

    i have got php5 installed.

    any idea?

  18. […] Per avere un’idea del funzionamento del sistema date un’occhiata al video in apertura, e per tutti gli altri dettagli visitate la pagina del programmatore. […]

  19. […] In order to use this app, you’ll need Mac OS X with HomeControl app and a built-in web server with enabled PHP. To download it for free and for more info, check out Brett Terpstra’s post. […]

  20. Natan says:

    I wrote a script to generate HTML for the application launcher. It isn’t great, but it works. See it at: https://​github​.com/​k​u​y​a​n​a​t​a​n​/​r​a​n​d​o​m​-​s​n​i​p​p​e​t​s​/​b​l​o​b​/​m​a​s​t​e​r​/​a​p​p​c​r​a​w​l​.sh Just for anyone who might be able to use it.

    • Brett says:

      Cool! My only concern would be that when you load the page from your server, by default it checks every process in the list to determine if it’s running. Because it’s doing that with AppleScript, the thread/memory control is pretty bad and a long list could probably hang the server… I haven’t tried it, though… how long a list have you been able to load?

      It wouldn’t be too difficult to remove the check for initial state and just check an app when it’s requested. For example, don’t have the switch show up when the page loads, tap the app name to check it’s state, then get the switch set to the correct on/off state for toggling. That would circumvent the whole issue, and you could run your entire Apps folder out of it.

      • Natan says:

        I’ve been able to load a list of about 54 applications. There /is/ a bit of lag when I go to the page, but not that much. I agree with your solution. As an alternative. you could remove the switches and just have a button that performs the same function.

        Oh, and I found out if an application’s name takes up too much space, then the on/off switches will be pushed down, pushing some of the switches below it with it.

  21. Natan says:

    For anyone who wants it, you can add these two lines:

    exec(“osascript –e ‘tell application \“System Events\” to set visible of process \”$app\” to true’”); exec(“osascript –e ‘tell application \“System Events\” to set frontmost of process \”$app\” to true’”);

    to

    function startapp($app) { exec(“osascript –e ‘tell application \”$app\” to launch’”,$response); if (isrunning($app) == “1”) return “$app launched”; else return “Error launching $app”; }

    between return “Error launching $app”; and the bracket to make the application you launch come to the front. (it’s in functions.php)

    • Natan says:

      Oh yeah, forgot to mention what it does – when you launch an application, it will set it’s visible and frontmost to true. Or, in other words, when you launch an application, it will come up in front of all your other open applications.

    • Brendy says:

      Kewl you should come up with that. Ecxenllet!

  22. Mary says:

    Hello there, just wandered by doing some research for a cell phone to home phone blog post. Truly more information that you can imagine on the web. Wasn’t exactly what I was looking for, but cool site. Have a great day.

Entries (RSS) and Comments (RSS), or Subscribe by Email