There comes a point, I guess, no matter how young you feel, where you realize you’re old.

My boys have their own computer where they play games I’ve installed which seem to not cross my boundaries for what’s ok for kids to play. One of the games I’m sort of on the fence about because it seems to bring out a lot of creativity, while also creating an unpredictable anxiety in them, is Minecraft.

So I limit their time with the game while I monitor their behavior surrounding their exposure to it. It’s not like it’s all that different from other games, but for some reason they get really into it and fight over who gets to play on the computer.

This means their computer gets lots of use. Which is cool, since it’s the laptop I bought back in 2008 that has been the bane of my professional life for at least 2 years. I put an SSD in it and 6 gigs of ram to buy it new life, so I’m glad it’s finding a useful retirement phase.

The thing is, though, my kids have never known or used a computer you turn off. The iPad and iPhones they’re used to just turn off when you’re done with them.

Without my guidance, they’ve discovered how to “turn off” the computer.

> Hit the mute button on the keyboard.
> Hit the power button on the monitor.

So I end up sitting here for much of the night after they go to bed half consciously trying to figure out why one of my devices is fans-ablaze until finally I realize that Minecraft taxes the shit out of that laptop and it’s been on since 8:00 with nobody even paying attention to Steve’s needs or intentions. (I think Steve is the Mincraft guy’s name…my kids call him Steve.)

I pick up the mouse, turn on the monitor, and Steve’s just standing there, staring into a wall or the sky or something. And the fans are at top speed trying to keep the processors and ram cool.

Command Q quits the game and within 30 seconds the fans whir down to silent. So, next step, after Ian’s potty trained, teach them how to quit a game on a computer that doesn’t just handle all that shit for you.

Computers that don’t need to be turned off, programs that don’t need to be quit, documents that don’t need to be saved, information that doesn’t need to be backed up, software that uses the same data source, no matter where you’re using it. That’s quickly making me feel old with these devices that were so transformative for me, so freeing, but are now so confounding to my kids.

Better Native PHP Syntax Support in Xcode

I’m a big fan of the Xcode IDE from Apple. Unfortunately, it is myopically focused on development for iOS and Mac OS X, using Objective-C. A long time ago, it was a lot more open. You could find a variety of plugins that would extend its functionality to include the projects you work with, outside of the Apple software ecosystem. But for the past several years Apple has made it difficult to extend the IDE beyond their intended purposes. I’m mainly a backend PHP developer, but I have been a long-time Mac user. This puts me in the position of having second-rate tools for the biggest reason I use my computer. Yes, there are IDEs for Mac OS X that focus on PHP, but they’re all cross-platform and written in Java, which is, itself, a second class citizen on the Mac platform.

I’ve suffered through using Netbeans, Eclipse, and PHPStorm for years, all the while yearning for a grown-up IDE like Xcode to do my job. No longer! With Xcode 4, Apple introduced CodeSnippets that allow a user to not only save commonly used code snippets to an easily accessible palette, but we can tokenize the snippets and define the prefix text to which Xcode’s autocomplete feature will respond. Type “fore…” and if you have a snippet called “foreach”, Xcode will offer up the helpful autocomplete list with your snippet. Hit tab or enter and the snippet will be inserted at the cursor. Hit tab again and you’ll be guided through the snippet’s tokens, one by one, allowing you to fill in the blanks.

With this in mind, I went to work creating over 5,000 snippets to cover the entirety of the PHP language. See my github repo here: https://github.com/tonyjohnston/PHP-Xcode-Autocomplete Now I have native-like autocomplete for Xcode. I start typing “str” and here’s what I see:

Screen Shot 2013-06-07 at 6.21.41 PM

I tap enter and this is what results:Screen Shot 2013-06-07 at 6.23.58 PM

I type “if” and Xcode presents this:Screen Shot 2013-06-07 at 6.25.17 PM

Arrow down to ifelse and tap enter:Screen Shot 2013-06-07 at 6.26.30 PM

Each of those blue rectangular ovals is a tabable token, just waiting for you to enter your specifics, just like Xcode’s support for Objective-C. It’s a huge advancement in the arena of Mac PHP IDEs. It took me about 6 hours to put this whole thing together so I’m sure that it can get better. Feel free to fork my GitHub repo for PHP Xcode Support and help make PHP a first class citizen on the only great IDE for the Mac.

I spent half an hour on the “service chat” with AT&T and eliminated $20 worth of overpriced services I wasn’t using. Here’s the script…

AT&T sales representatives are happy to assist you with your questions. AT&T sales representatives will not have access to your personal account. This service is provided to you under AT&Ts Terms and Conditions and Privacy Policy. 

You are now chatting with Lorena, an AT&T sales representative.

Lorena: Welcome to AT&T online Feature Sales. How may I assist you with your features today?
Tony: I’m only using about 10% of my data plan. How can I choose a cheaper plan?
Lorena: I’d be happy to help you with our features today, Tony. Which data plan do you have now?
Tony: Or, if it’s possible, how can I add data and device tethering so that I can drop my home internet and just tether to my phone?
Tony: It looks like I’ve got Data Pro 2GB LTE
Tony: for iPhone
Lorena: The tethering/hotspot data plan is the 5GB for $50 if you wanted to do that. If you want to lower your data plan, we do have the 300MB for $20 that you can switch to. You wouldn’t be able to tether/hotspot with your phone unless you have the 5GB.
Tony: hm. No, I guess that’s not a better option. I get unlimited data via my cable provider for $47.
Tony: so it’s $25 for 2gb and $20 for 300mb?
Lorena: That’s correct. The 2GB data plan is no longer available though so once you switch from it, you won’t be bale to get it back.
Tony: what is available now?
Tony: The only option I see is the one I currently have.
Lorena: The 300MB for $20 and the 3GB for $30.
Tony: huh. that’s crappy.
Tony: Is there any way for you to look at my plan and usage and suggest something that could save me money?
Lorena: We actually do not have access to the accounts through chat since we are guides. We are available to assist you with managing your account online and changing features online through the self-service system. Which other plans and features do you have?
Tony: What’s the cheapest iPhone plan available?
Lorena: Do you like to text?
Tony: I’ve probably got a year left on my current contract.
Tony: Well, yeah, but text plans are more expensive than they’re worth. If it saves me money I can start using Facebook messaging.
Tony: Can you tell me what the cheapest iPhone plan is?
Lorena: Well, if you did the 450 Nation Talk Plan with the 300MB data plan, you’re looking at $59.99 a month before taxes without any messaging. Unlimited Messaging is $20 if you wanted to add it.
Lorena: Do you have just one line on your account?
Tony: Yes
Lorena: Thank you. Do you know which voice plan you have?
Tony: So, I have $25 data, $5 text. My current charges before taxes and fees is $80./
Tony: If I drop the data to 300mb and ditch the text plan, that would still only bring me down to $70.
Lorena: Do you know which voice plan you have?
Tony: Do you know where on the website I can find that?
Lorena: Do you see the myAT&T tab at the top? Please mouse over the word “Wireless” below it. You’ll see a drop box appear and you can select “Change Rate Plan” from there.
Tony: Oh, I have Family Talk Nation 550 with Rollover.
Lorena: Thank you. That’s odd. We can certainly switch you to an individual plan if you have just the 1 line on your account.
Tony: That appears t be the cheapest.
Tony: Can you do that right now or is it something I need to do on the website?
Lorena: Our Care chat is available now to do the switch for you since I do not have access to the accounts through this chat.
Tony: I don’t know what that means.
Lorena: The 450 Nation Talk Plan would be the smallest voice plan for individuals and is $20 less than the 550. Would you like to change your data plan before I transfer you over?
Tony: Oh man. That would be great! I didn’t realize I was paying $20 more than I need to. I almost never talk on the phone.
Lorena: Ok! I can certainly transfer you over so our Customer Care team can change your plan for you. Would you like to change your data plan before I transfer you over?
Tony: No, if I can save $20 by changing my voice plan I don’t need the $5 extra to have a crappy data plan.
Lorena: Alrighty. Give me just a moment to transfer you over.
Tony: Thank you!

Please wait while I transfer you to an operator at AT&T Wireless Customer Care.
Welcome! You are now chatting with ‘Chara Cooper’.

Chara Cooper: Hello Tony
Tony: Hi Chara.
Chara Cooper: thank you for chatting in with me today
Chara Cooper: how can i help you?
Tony: You’re welcome.
Chara Cooper: so How can i do you tonight my dear.
Tony: So Lorena was helping come up with a way to minimize the total cost of my plan based on my usage. She said that there’s a cheaper voice plan than what I’ve got and I’m paying $20 more than I need to since I rarely actually use my phone as a phone.
Tony: She suggested the 450 Nation Talk plan.
Chara Cooper: what kind of phone do you have Tony?
Tony: Is that the cheapest voice plan?
Chara Cooper: okay, what kind of phone do you have?
Tony: It’s an iPhone 5.
Chara Cooper: okay so you can get a regular nation plan, but because you have a smartpone you are required to have a data plan with that.
Chara Cooper: yes because it is a smart phone
Tony: Well, yeah. If I could have data only that’s what I’d go with. My phone is rarely at my ear. Is there a plan that drops voice service?
Chara Cooper: LOL:) no honey.
Chara Cooper: that would be nice though.
Tony: If not, I just want to know what is the cheapest voice plan I have to agree to.
Tony: My bill starts out at $80 a month right now. When I got my first iPhone that was $60. But I can’t find a way to get it back down to $60 on the website.
Chara Cooper: tony pleas give me your cell number area code first
Tony: ###-##4-5666
Tony: ###-##-GLOOM, if that helps.
Tony: I gotta hurry through this. My kids are exploiting my distraction to stay up past their bed time.
Chara Cooper: :))) thats funny and cute
Tony: 🙂
Chara Cooper: whats the last four digits of your social please?
Tony: ####
Chara Cooper: thank you Tony.
Tony: Is it against the rules for you to just tell me which is the cheapest voice plan? Because that’s all I really need to know. I just want to switch to the government mandated minimum plan since I hate talking on the phone and only put up with people calling me because having the internet in my pocket makes me all powerful.
Chara Cooper: okay Tony Im looking at your account
Chara Cooper: and i do see that you are on the 550 plan
Tony: yes.
Chara Cooper: you can move to the 450
Chara Cooper: and keep the data pro
Tony: and save $20?
Chara Cooper: is that absolutely.
Chara Cooper: i meant
Chara Cooper: absolutely!!!
Tony: hahaha…
Tony: ok. do it.
Chara Cooper: okay sure.
Tony: Also, block calls from my ex girlfriend.
Chara Cooper: :)))) too bad for her.
Tony: hehe
Chara Cooper: lol!!
Chara Cooper: you men are funny
Tony: Just kidding. All of my exes love me.
Tony: Well there’s this one who still hates me.
Chara Cooper: are you an aries
Chara Cooper: or a sagittarius
Tony: If I give you her name can you block her?
Tony: No. The opposite. Virgo.
Tony: Ok, I gotta get out of here. The kids are taking over the asylum.
Tony: You got me taken care of?
Tony: Or is there something else I need to do?
Chara Cooper: illl text you the information
Chara Cooper: good night
Tony: cool. Thanks, Chara!
Tony: Have a good night.
Chara Cooper: your welcome
Chara Cooper: I will send a trext to confirm that the plan has been changed for you to nation 450
Tony: great. thanks for your help and your sense of humor 😉
Chara Cooper: 🙂 your welcome.

I installed Mac OS X Mountain Lion, and uninstalled Adobe Flash

I’m uninstalling Flash. Let’s see how it goes. They’ve never had a good Mac client and it’s a dying technology that won’t stop interrupting me to force system updates. If I wanted constant, disruptive software updates I’d still be using Firefox and and I’d switch to Windows.

Speaking of which, I spun up a new VM and installed XP today. When I went to download the hundreds of patches that are standard when you install XP from a CD, Windows Update 404’d. I haven’t really been keeping up to date, but did MS stop all XP support, including Windows Update?

How to run PHP scripts inside your Objective-C Mac OS X application

Picking a starting point

I spent a lot of time looking around the web for instruction on how to execute PHP inside of a Mac OS X application created in Xcode (version 4.3) only to find a whole lot of nothing. I knew it could be done since there are several apps in the Mac App Store that allow you to interpret PHP on the fly, so I set out to do it without the help I believed I needed. It turns out to be one of the easiest things I’ve done in Objective-C.

The first thing I did was to download the JavaScript Interpreter sample code from the Apple developer site for reference. It’s old code and doesn’t compile readily on a 64 bit system with the OS X Lion SDK, so to get it to run I had to change the target to fit my system as shown below. Xcode will also ask you if you want to update the code to current standards – go ahead and do that.

Xcode screenshot

Getting Objective-C to execute PHP scripts

Next, I changed the code to skip the JavaScript interpreter and use PHP instead. This involves the NSTask Class from the Foundation Framework. Luckily the Foundation Framework is already included in the JSInterpreter sample code. While we’re talking about included Frameworks, you can go ahead and remove the reference to the JavaScript Framework now. To get rid of the red squiggly lines and error messages, delete the #import directive at the top of the MyController.m file along with all of the code inside the evaluateScript method.

Next, I searched for a way to run a command line script similar to “> php testing.php” that would allow me to execute a script and see its output. As always, Stack Overflow came to my rescue. I took the basics of the code there and went to (not very much) work.

First, I had to replace the NSTask LaunchPath with the php binary executable on my system, which is at /usr/bin/php.

Next I had to replace the arguments with the code I wanted to run, which was at ~/tonyj/Sites/harikari/test/testing.php – a script that simply echos “Hello world!” To keep from having to alter the existing code too much, I put in the whole path but left out the filename so that I could type it into the input field of the original application and have it executed when I clicked the button.

That’s it. I built and ran the application and I had a window with an input field and an output filed. I typed the name of my script into the input field and, ta-da!, “Hello world!” appeared in the output field.

A standalone application?

Next I wanted to see if I could make the whole thing a standalone application. This being my first attempt at writing a Mac OS X application in Xcode, I had no idea where to start. So I just went for it. I added my PHP binary to my application (File -> Add Files to JSInterpreter) and then added my script to the project. I wasn’t quite sure what the path was going to be for either of them in the application bundle, so I went back to Stack Overflow to find out about [NSBundle mainBundle] resourcePath] as a method for getting the path to the inside of your application, wherever it may be.

It worked!

With one caveat: I haven’t worked through all of the details yet, so I’m sure there are some dependencies in the PHP binary that my system provides in the place that PHP is looking for them. But I’m confident that it would not be difficult to find and eliminate or compensate for them.

Also, Objective-C doesn’t automatically wait for the return value from a task the way PHP does. And PHP is sometimes a little slow to respond. So you have to figure out how to make it wait around for a response from PHP and your script, especially if it’s a lengthy one. Once again, Stack Overflow helped me find information about the NSNotificationCenter. I don’t know much about it, but it basically notifies your code when the PHP output file is done loading.

Now I can load any PHP script into my application and send and receive messages to and from it. I might try adding MySQL tomorrow.

The code:

Fork me on GitHub

-(NSString *) evaluateScript:(NSString*)scriptName
{
    NSTask *task = [[NSTask alloc] init];
    NSString *taskPath =
        [NSString stringWithFormat:@"%@/%@",
        [[NSBundle mainBundle] resourcePath], @"php"];
    [task setLaunchPath: taskPath];

    NSArray *args;
    NSString* scriptPath =
        [NSString stringWithFormat:@"%@/%@",
        [[NSBundle mainBundle] resourcePath], scriptName];
    NSLog(@"script file path: %@",scriptPath);
    args = [NSArray arrayWithObjects:scriptPath, nil];
    [task setArguments: args];

    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];

    NSFileHandle *file = [pipe fileHandleForReading];
    [file waitForDataInBackgroundAndNotify];
    [[NSNotificationCenter defaultCenter]
 addObserver:self 
           selector:@selector(receivedData:) 
               name:NSFileHandleDataAvailableNotification 
             object:file];
    [task launch];

    NSData *data = [file readDataToEndOfFile];
    NSString *string =
        [[NSString alloc] initWithData: data
 encoding: NSUTF8StringEncoding];

    return string;
}

- (void)receivedData:(NSNotification *)notif {
    NSFileHandle *file = [notif object];
    NSData *data = [file availableData];
    NSString *str = [[NSString alloc] initWithData:data
 encoding:NSASCIIStringEncoding];
    NSLog(@"%@",str);
}

Altering the code

This is an example of how to type in the name of any file included in your project, but you may want to just execute raw PHP commands or fully integrate PHP into your app. To do this, just look at the line above where the args variable is set. You want your array to have filepath as its first element, then any arguments you want to have available in the argv[] array.

If you want to execute single PHP functions, your first arg will be “-r”, followed by the function as in the following example.

args = [NSArray arrayWithObjects:@"-r",@"is_array(array(1,2,3))", nil];

Apple TV 2.3 Finally Includes Video Playlists, 3rd Party Remotes

Here’s a quick note to update my ongoing struggle to ensure that my Apple TV doesn’t fall out of usefulness before its time. As you may remember I posted several months ago a wishlist for Apple’s next Apple TV update. It included some of the obvious things like responsiveness, performance, and video playlists. Unfortunately, none of these luxuries were included in the last update.

Apple TV 2.3, however, does actually seem to address many of the issues I pointed out in my last Apple TV post. The remote actually elicits an almost immediate visual response from the unit. There aren’t quite so many moments where I’m asking myself, “did that button press register?” It still happens, but I would say it’s quite less frequent now.

Two great features have been added with this update: 3rd party remote control support and video playlists.

Video playlists: Now you can play uninterrupted video through all of your day’s video podcast subscriptions. You can also set a video playlist to last through your New Year’s Eve party. Just create a playlist of videos on either a shared library or on your Apple TV’s main linked and synced computer.

This feature is great because now you can play each of your 2 or 3 minute podcasts from your favorite sources back to back as you turn to jello on the couch after a long day of hard brain stuff. You can create channels based on content and sit, motionless until every last one of those suckers has played.

3rd Party Remotes: Let your inner couch potato rejoice. Finally you can assign 6 of those extra buttons on ANY remote control littering your coffee table to the 6 functions of that little white remote that came with your Apple TV. Just enter Settings, Remotes, and start pushing buttons. It doesn’t matter which button you push on whatever infrared remote you have, as long as it doesn’t interfere with the main function of the device the 3rd party remote came with, you can repurpose the button for your Apple TV.

One sad note, Boxee was wiped out. I no longer have access to Hulu, Comedy Central, MySpace TV, and Torrents. And from what I’ve read, it’s not re-installable at the moment. However, I’d venture that most Apple TV users will enjoy the new features enough to make the update worth it anyway. While the Boxee crew will likely be hard at work creating a new installer and have you back on the Internet TV IV before the DTs have a chance to give you dead ceiling baby nightmares.

Also, I’ve got a few Boxee invites, so let me know if you’re interested in the comments.

Synergy – Dual Monitor Desktop Solution for MacBook Pro

 

Synergy-enabled Multi-monitor Desktop Solution for MacBook Pro

Have you ever been sitting at your desk with your laptop open, working away on your dual-monitor desktop setup and thoughtlessly tried to move your mouse from your desktop monitor straight over to your laptop? What about copying a URL to the clipboard of your laptop then jumped over to your desktop to try to paste it into an email? It doesn’t work, right?

Well now it can. Synergy is an open source project that allows you to do just that. Install it on your windows desktop and your MacBook, take a few minutes to configure it, and voila! You’ve just created the perfect dual monitor, multi-operating system desktop work environment. 

You can now seamlessly move your mouse monitor to monitor to laptop and copy from one operating system and paste into another.

In my own setup, I’ve connected the keyboard and mouse via bluetooth and the left-side monitor to the Windows XP box sitting under my desk, and the center monitor to the MacBook Pro. Running Synergy on the Windows box in server mode and client mode on the MacBook, I now have a fully integrated multi-monitor desktop and laptop combo.

Apple TV Take Two – A few criticisms

Now, I’ve heard my share of the complaints about the new interface. I, too, had problems with it right at first. It’s something you have to get used to. You have to learn that there is no “sources” menu. You have to accept that what’s been synched with your Apple TV is undifferentiated from what’s in your iTunes library. However, you can adjust. Humans have adapted for millennia to things far worse than a new digital media menu.

So, now to my criticisms… The new interface is fine. But don’t like the weird synching behavior. I have to go downstairs to my G5 to initiate a synch of the podcasts that used to be synched automatically throughout the day so that they were there when I got home. I have a new option — Automatic Synch. It’s a mystifying, magical process where iTunes decides what to synch. It takes hours and, in the end, you have no idea what’s going to be synched.

Another new feature, which I adore, is the ability to direct audio output to any other connected output device, including the Apple TV, on your network. This includes any Airtunes receivers, wireless speakers, networked computers, and even some windows media extenders. A fantastic addition that allows you to enjoy internet radio over your central HiFi system. Or whatever it is you have.

Perplexingly, Apple has not made similar functionality available for video. DEAR APPLE, I want to share my DVD drive on my main Mac downstairs with my Apple TV. I want to create video playlists that allow me to group certain types of content into a single, endless, video stream. With over 10 new podcast episodes to watch each day, it would be fantastic to create a smart video playlist where I can hit play a single time and watch all new podcasts. The fact that I can’t reeks of marketing shenanigans and defies the image Apple has earned inside my mind.

The streaming of podcasts, live, from Apple has me flummoxed. Why can’t the menu tell me when there’s a new episode available of a podcast I pay attention to? Why can’t I group a day’s worth of podcasts into a playlist where I hit play once and I have an hour’s entertainment in front of me?

I love renting movies from my couch and I can’t wait till the library is full and more inviting. But Apple really needs to pull it together in order to make me adore this platform. Yes, I understand the need to gear the box toward streams of revenue, but until they can offer a full entertainment package at a reasonable price, I will be unhappy with a device I can’t custom fit to the needs of my nightly allotment of time toward passive entertainment.

So, though I doubt it, if Apple or any of the Apple staff are watching my blog, I’m available for a consultation. I charge $75 per hour, and though I understand that’s ridiculously cheap, I only want to help right some of the wrongs I’ve encountered in the past two years of Apple product development after a lifetime of being surprised by the continual forward thinking aesthetic of Apple’s product quality. In being a tried and true Mac user for two decades, I think I know when I see a solid reputation heading toward disaster.

iPhone Lust

I made a very clear and sensible decision to stay clear of the iPhone hype. I don’t need a phone that does all that. Actually, I have a phone that browses the web, gets my email, wi-fi, bluetooth, mp3, and a gorgeous screen. I use the phone feature only.

Unfortunately, I have friends who are not as budget conscious as I am and were able to stand in line yesterday to get their mitts on an iPhone. We were all out having drinks to celebrate the semi-retirement of a brilliant and lucky buddy in his mid thirties who arrived half an hour late with his brand new iPhone. It was un-activated, so all we could do was marvel at the form factor, which was enough.

It’s smaller than you think it’s going to be. It’s a bit shorter than my T-Mobile SDA and narrower than an iPod. Fits nicely into my pocket with no uncomfortable bulk. Unactivated, it allows you to look at the main screen and slide the slider for an “Emergency Call”. The numeric keypad pops up so you can dial 911, I guess.

Later, Solomon showed up with his brand new, activated iPhone. That was pretty much the end of my social interaction. The world went silent and my vision went tunnel. It works exactly like they say it will. Typing is something you have to get used to, but you will. You’ll want to start out by holding your finger down on the keyboard until you have the letter you want. This allows you to slide a little to the left to get O instead of P, or a little up to get N instead of the space bar. Or, just type as fast as you can and trust that iPhone will correct you correctly when you hit the space bar. It’s pretty slick.

Internet is decently fast, and for the applications I can see myself using, perfectly fast enough. YouTube videos take a while to buffer, but once they start playing they’re solid.

We played around with the contacts list a bit, which was actually fun. Tap the edit button and then the contact picture icon, point at your friend, and grab a picture of them for their profile. Then when you contact them or they contact you, the background is filled with the designated picture, full screen.

The magnifying glass positioning tool is amazing. In fact, the way everything you’re tapping on pops up in a graphic above your finger so that you know what the phone thinks you’re touching is a fantastic innovation. Somebody at Apple must hate styluses as much as I do. This finger as stylus thing is brilliant, and brilliantly executed.

So, yes. Now I want one. Even though I don’t need it. It’s pretty much the greatest phone experience I’ve ever had. Even if it was fleeting.