Jul 09 2008

Restart TwonkyMedia after scheduled sleep

Published by Jonathan Wise under Hacks

In our house, a Mac Mini serves at the content library and retreival machine. It runs a Torrent client, iTunes, and TVShows to collect and organize all our media. At night it runs a number of scheduled tasks to keep things orderly and fresh, and when its done (at about 4:00am) it goes to sleep until 8:00am when my wife will want to use it again.

TwonkyMedia server, which is delivering our non-iTunes content onto the AppleTV (via the MediaCloud uPnP client) has a problem with this. It doesn’t recover well from sleep.

The solution is to run an AppleScript every morning at 8:01 to re-start TwonkyMedia. This little AppleScript will access Twonky’s built-in shell script to shut down any running instances, and start-up a fresh one:

do shell script "/Applications/MediaServer.app/Contents/MacOS/twonkymedia.sh &> /dev/null &"

The “&> /dev/null &” sends the shell script’s output to oblivion so that AppleScript doesn’t hang waiting for the server to start-up.

The only annoying part about this is that every time TwonkyMedia starts up, it wants to take you to its home page in your browser. Follow these directions to make TwonkyMedia start-up silently (last post on the page.)

No responses yet

Jun 27 2008

Learning to Develop for the Mac - Historically

Published by Jonathan Wise under Articles

Going back to the beginning, and learning Project Builder, Interface Builder and ObjectiveC on NextStep. Can you believe this is the technology that NeXT had the same year Windows 3.1 came out? And its the same stuff that’s used to build Mac and iPhone apps today…

Click for a bigger picture.

In fact, the technology is so close that I used a tutorial for developing a sample Mac app, to develop a sample NextStep app. The notion of “FAT Binaries” that work on multiple hardware architectures came from NeXT as well, since it ran on any number of platforms by the end.

No responses yet

Jun 26 2008

Installing NextStep 3.3 on VMWare 6

Published by Jonathan Wise under Articles, Hacks

I’ve been hankering to learn more about the origins of OS X, so I figured the best place to start would be the OS at its core — NextStep (later named OpenStep.)

When Steve Jobs was ousted from Apple, he set out to create a new company that would deliver elite hardware, and a revolutionary operating system. NeXT was started to build powerful hardware and software that would leapfrog the Mac (and everyone else on the market.) They eventually had to kill off the hardware line (after making some very nice, uber-high-end machines) but the software they made changed the industry. It was on a NextStation computer, using the NextStep OS that Tim Berners Lee would invent the World Wide Web, and its the true Object Oriented approach of the OS that many companies have imitated or borrowed.

By the mid-90s Apple was in truly rough shape. Their archaic OS, once the greatest thing on the market, was showing its age, and Apple had tried, and failed (mostly due to mismanagement) to replace it. It was determined that they should buy an existing next-gen OS, and re-build on top of it. After flirting with IBM and BeOS, they settled on a deal with NeXT. A deal that grew until Apple acquired the company, re-acquiring Steve Jobs in the process. He became the iCEO (interim CEO) and the de-facto leader of the company. Existing ideas were rapidly brought over from the Mac onto NextStep/OpenStep, layered on top of its rock-solid BSD Mach microkernel, Object Oriented underpinnings, and a re-vamped version of its graphics layer, was a new Interface, and a Classic emulator to allow old Mac apps to run.

The end product, after many variations, pre-releases, betas, and one or two fairly ugly general releases, was what we know today as Mac OS X. Much of NextStep is still intact, including low-level OS APIs, visual and development concepts, and culture.

If you’re interested in getting NextStep up and running in VMWare (I’m using a Windows Vista 64-Bit Host OS, but these steps should work with most versions of VMWare — including Fusion) you’ll need to find an ISO of the NextStep OS somewhere, and maybe these steps will help you…

Continue Reading »

One response so far

Jan 27 2008

Using Mail.app with multiple users — using AppleScript: Part 2

Published by Jonathan Wise under Hacks

The previous post, about hacking multi-user support into Mail.app, seems to have struck a chord, and there have been lots of great questions about how to extend the script, or customize its behavior or appearance. Things tend to get lost in the comments, so I figured I’d create a part 2 to answer some of the questions that have popped up. If you haven’t already, check out part 1 to get caught up.

Some of these might seem a little basic to long-time users, but lets remember that not everyone has been using a Mac since OS 7 (or earlier!) and cut the newly Mac-faithful some slack…

Evan asks: Absolutely perfect, exactly what I was looking for. Well, almost. How about adding a 3rd account?

A third account is done very easily by modifying the script slightly. (Update: If you’d like to do more than 3 accounts, see the solution in the comments which changes our user interface to a listbox)

The first thing you’ll want to do is update our crude little user interface to ask about the third account. This line here decides what options show up in the dialog box:

display dialog "Choose the Mail account to use" buttons {"Jon", "Nicole"} default button 1 with icon note

You can add as many up to 3 options as you want, just by comma seperating them, so instead of {”Jon”, “Nicole”} you could have {”Jon”, “Nicole”, “Yoda”}
Then you need to modify the “if” statement to support each individual referred to. In the original we said:

if the button returned of the result is "Jon" then
-- do stuff to change account to Jon
else
-- do stuff to change account to Nicole
end if


The else is a problem now because it assumes only two conditions. Instead of an else, we can do an else if — one for each individual we want to switch between:

if the button returned of the result is "Jon" then
-- do stuff to change account to Jon
else if the button returned of the result is "Nicole" then
-- do stuff to change account to Nicole
else if the button returned of the result is "Yoda" then
-- do stuff to change account to Luke
end if


Inside each condition you’ll need to disable all the other accounts (set enabled to account X to false) and then enable the account they’ve chosen.

Eric asks: I would like to attach to the script the mail icon or a similar icon. Then when I added it to the dock, it is more obvious to click it to run.

This is one of those tricks that long time Mac users will know well, but is not very obvious for newer converts. You can copy and paste any icon from any application/document/folder to any other in the finder. Just click on the icon you want to “borrow” from and hit Apple + I for “Get Info.” In the info dialog, click on the icon and hit Apple + C to copy the icon to the clipboard. Now find your target icon (such as the script you just made) and “Get Info” on it, click the icon in the dialog and this time hit Apple + P to paste. Now you have a pretty icon!

Note: This will be limited by permissions, so if your user doesn’t have permission to ‘write’ to the target object, you won’t be able to paste.

Eric, having figured out the above on his own, then asks: My 2 problems are: 1, I can not add the script to the dock. 2, when I click the script icon, it take me to the editor where I then have to click RUN.

A script, by itself is just a document. In order to make it into a runable application, you have to save it as such in Script Editor. From the File / Save As… dialog change the File Format to “application.”

Under most circumstances you won’t want to check the box for ‘Run Only’ because once you do, you cannot edit it in Script Editor again. Also, uncheck the box for ‘Startup Screen’ to make it run a little more gracefully.

You may also find that the Dock is not the best place for your script — since it will essentially give you two Mail icons. What I did instead was to enable the AppleScript menu and use that for all my common scripts.

If you want to do this, open the Application AppleScript Utility in the AppleScript folder and check the box for ‘Show Script Menu in the menu bar.’ You may also want to uncheck the box for “Show Library scripts” to hide the example scripts Apple includes to make your menu shorter.

Note: For scripts to show up in this menu you’ll have to save them where your Mac expects your scripts to be: In your user’s Library folder you’ll find a folder called “Scripts.” Put them, or an alias to them, in there.

8 responses so far

Jan 08 2008

XBox360 + Connect360 + Linksys WRT54g (firmware hacked)

Published by Jonathan Wise under Hacks, Reviews

Nullriver’s Connect360 is a fantastic little app that you can run on your Mac that will fool your XBox 360 into thinking its talking to a PC, allowing you to share your iTunes, iPhoto and video libraries with the 360 dashboard. The video transcoding is a little lossy, but for SD applications it works exactly as advertised. Well worth the $20 they’re asking.

According to the Connect360 Support website, you can’t use Connect360 on your Mac to connect to your XBox 360 if your network uses a Linksys WRT54g with homebrew firmware on it. They’re right — it doesn’t work.

The solution is pretty simple, however. Abstract the Mac and the XBox from the router using a good* network switch. The switch will allow the two devices to communicate (via broadcast) with each other without having to go through the router, and all will work as expected.

*Note: The Connect360 site also warns that some switches may cause a similar problem. I’m using a NetGear Gigabit Switch to accomplish this, and it works perfectly. YMMV.

3 responses so far

Jan 06 2008

Using Mail.app with multiple users — using AppleScript!

Published by Jonathan Wise under Code Snippets, Hacks

OK, this is pretty brilliant — and SO simple.

Here’s the setup: my wife and I share a Mac at home. For memory reasons, among others, I don’t want to use Fast User Switching, and because of my automated tasks, I don’t want the primary account to ever be logged out. So all many of our programs need to be set-up for two different users. Firefox has user profiles, that once configured, works perfect. Mail.app has no such thing. What I decided to then, was write an AppleScript that would switch Mail.app between users for us. This example is for two users, but it could be edited for more. Here’s how to use it:

  • Setup Mail accounts for each user
  • Modify the script to prompt for each user you have, and reference their account name
  • Replace your Mail.app dock icon with a link to your AppleScript (you can even give it the Mail.app icon)
  • Whenever you launch Mail, you’ll be asked which user you want to use
  • Even better than that, you can switch users just by clicking the Mail icon in your dock again. You don’t even have to close down Mail!

The result looks like this whenever you invoke the script, and launches/reconfigures Mail within two seconds. Set the delay to longer if Mail.app takes longer to start on your Mac.

The code is dead simple, and took me only moments to put together. Note that the delays and the order in which things are done is important so that it doesn’t hang waiting for Mail to start if its not already open.

-- Mail Account Chooser, by Jonathan Wise
-- Add user profiles to Mail.app
display dialog "Choose the Mail account to use" buttons {"Jon", "Nicole"} default button 1 with icon note
if the button returned of the result is "Jon" then
  tell application "Mail"
    activate
    delay 2
    set enabled of account "Nicole Home" to false
    set enabled of account "Jon Home" to true
  end tell
else
  tell application "Mail"
    activate
    delay 2
    set enabled of account "Jon Home" to false
    set enabled of account "Nicole Home" to true
  end tell
end if

11 responses so far

Nov 05 2007

Leopard doesn’t quite stack up

Published by Jonathan Wise under Articles

I’m a Mac fan boy, and I’m very tolerant of change. When the Mac using world screamed when they replaced OS 9 with OS X, killing a lot of the nice functionality in OS 9 in favor of a brand new OS, I drank the kool-aid and made the change as soon as I could.

And I’ve been a big fan of each major revision of X — and have run all of them right out of the gate, warts and all. But I’m not sold on Leopard.

The loudest touted features are either useless, or already existed in 3rd party apps for 10.4.
- Spaces is just VirtuDesktops — and a concept I never had any use for. I’d much rather have multiple monitors then multiple “virtual” screens.
- TimeMachine is just a back-up app — granted its well integrated and looks pretty. But the method I have in place now is much less intrusive (not to mention more fire-proof) and doesn’t require me to be tethered to a local external hard drive.

But nothing bugs me more than Stacks…
Stacks kills a feature I’ve used and loved in OS X since they killed the Apple menu’s hierarchical app-launching capabilities from OS 9.

It used to be, in OS X 10.2-10.4, that you could drop any folder onto the right side of the Dock and turn it into a menu by right clicking on it. In this way I could add my very organized Applications folder to my Dock and use it to find applications in a very simple manor (I’ll admit, its kind of like a Start Menu, but come on — its a good way to organize your apps).

In 10.5 that great feature was replaced with either a silly, and surprisingly static, curved list, or a box full of icons. Now that box can contain subfolders — but if you click on them, it opens a window. That’s a window you have to close after you find your application. Unacceptably stupid.

Know what else is stupid? Apparently there’s a massive data loss bug in the new Finder. For years — literally, we’ve been complaining about how awful the Finder is (even compared to its OS 9 grandparent) and this is the fix they offer us?

Damage to the Dock and a bad upgrade for the Finder aside (I do like the new sidebar, btw) Stacks are not what they were supposed to be. A “Stack” was designed as a replacement for (or addition to) the folder concept. It was an organizational item that existed in the Finder, had a single icon that could be dragged around like a file, but expanded when clicked to show a collection of items. There are plenty of UI prototype videos on the web showing what Stacks meant to us before Apple polluted the term.

I’m ditching Leopard for the time being. The only feature I really wanted was the improved Front Row… maybe there’s a way I can run it in 10.4. If not, I’ll just hold out hope that Apple gets their crap together with upcoming updates.

Update: Yay! It looks like they fixed stacks… a little bit!

4 responses so far

Oct 14 2007

Enabling WebDAV on OS X

Published by Jonathan Wise under Links

I won’t re-write the article, but this weekend I wanted to turn on WebDAV on my Mac mini, and this article pretty much covered it for me. The article talks about using iCal, but do the steps and see the FAQ for additional tips on regular file sharing.
The only note I’d add is that Digest authentication didn’t work for me in OS X 10.4.10 — I had to use Basic authentication.

No responses yet

Sep 21 2007

Generating RSA Keypairs on Mac OS X for a *nix web-server

Published by Jonathan Wise under Hacks

I’m sure there are many of you who have long been comfortable with RSA keypairs, so I post this as much for my own reference, as for those like me who stumble around the Internet trying to find coherent instructions on how to do this. These instructions work for OS X 10.4 — not sure about other versions or *nixes. I plan to apply them to securing SSH on my iPhone for easier file transfers though.

Step 1: Open Terminal
Usually found in the Utilities folder of Applications (but if you didn’t know that already, this might not be the right topic for you!)

Step 2: Create your public/private key pair on your local computer

  • At the command prompt type: ssh-keygen -t rsa
  • Hit enter to accept the default file name and location

Step 3: Copy your public key contents into the “authorized_keys2″ file on the remote server

  • Type: ssh username@remoteserver.com ‘cat >> ~/.ssh/authorized_keys2′ < /Users/Youruser/.ssh/id_rsa.pub
  • Enter your FTP password for the remote server when prompted
    • If the file didn’t already exist on the remote server, it will be created, don’t worry.

Step 4: SSH at will!
You will never need a password from your account on your local computer again! Note that you’ll need a public key provided for each client computer/computer account you want to use to connect to the server.

One response so far

Sep 20 2007

Address Book vCard Publishing with AppleScript and SCP

Published by Jonathan Wise under Hacks

The one piece of my .Mac replacement I’ve been missing is a way to publish our address book to the web. Every different web mail app has its own address book, and none of them sync with each other, with Outlook or, for me, Address Book.app — rendering all of them useless. So I needed my own way to, in a pinch, get addresses online. vCard PHP provides the parser and renderer, but I, obviously, needed to provide the group vCard for it to show me. Enter AppleScript again.

The goal of this script was to invoke Address Book.app’s Export command on all of the contacts in its database. I found a script online that exported individual vCards, so with a little modification I was able to get it to dump out a single group vCard. The next challenge was getting it up to my webserver.

I’m learning UNIX as well as AppleScript, so I was quite happy to put SCP to work. However, I hit a brick wall when trying to get AppleScript to pass in my server password. It can’t do it. I searched all over the Internets, but apparently once AppleScript invokes SCP, it loses control. And SCP obviously doesn’t have an AppleScript dictionary of commands. This behaviour is quite different from SSH, with which you do not lose control.

This sucked for a long time, until I finally broke down and decided to learn about RSA key pairs for authentication. I’ve been avoiding this for quite awhile now, because I frankly like just using a password, and I was scared of learning such an obscure new topic. But I finally figured it out — although that’s a topic for another post…

Anyway, assuming you have key pairs set up with your server, this script will do the trick. As I mentioned, it exports your Address Book to a group vCard in a given folder on your local hard machine, then SCPs the file up to a given folder on your web server. Point vCard PHP to that file, and schedule the AppleScript to run at a specific time using iCal, and you have an updated Address Book online!

Download the Script Here

One response so far

Next »