♦ Screen sharing on OS X Lion without asking

Mac OS X’s built-in Screen Sharing feature changed slightly between Snow Leopard and Lion. Before, it was a straight-up [VNC](http://en.wikipedia.org/wiki/Virtual_Network_Computing) server, and you could connect to and control the remote computer with just a password. With Lion, when you try and connect to a machine using the built-in [Screen Sharing app](http://docs.info.apple.com/article.html?path=Mac/10.6/en/14065.html), you get this pop-up:

Screen Shot 2012 01 01 at 2 23 26 PM

This happens when the remote computer has someone logged in with a different account than yours — in this case, my wife’s account is logged in, and I want to go in and troubleshoot something remotely. (This doesn’t happen if you have the same username and password on both machines, but I haven’t been able to test this.)

This new behaviour is useful if you want to log in to your own account, without disturbing whoever’s using the computer. My problem, though, is with having to “ask to share the display”: what if there’s nobody on the other side to click “allow”? This happens to me regularly when I’m out, or errm when I’m in the bedroom and don’t want to walk to the living room _don’t judge me!_ ermm.

Turns out there are a couple of ways to get around this, as long as you have the currently logged-in user’s password:

__Connect via Finder__. This works best on a local network, when you can see your other computer under the “SHARED” panel on the Finder’s sidebar. Clicking “Share Screen” will bring up some options:


From here, you can log in as the current user, and not have to ask for permission.

__Send user and password in VNC request__. Just log in as follows when Screen Sharing asks for where to connect:


…and you’ll get into that user’s screen, no questions asked. This works a few ways, e.g. by entering this into the “connect” dialogue box of the Screen Sharing app (in /System/Library/Core Services), in Terminal.app:

“open vnc://user:password@server-address“

Finally, you can save “vnc://user:password@server-address“ as a bookmark in Safari. Note that storing your account password in a bookmark is probably a terrible idea, but then, so is having to get up from the bedroom to walk to the living room.

♦ Applescript to add +65 prefix to Address Book →

A very useful AppleScript by [Jeremy Foo](http://twitter.com/echoz) to add a +65 Singapore country code prefix to any 8-digit number. Run this script* if you’d like to use your email address as your iMessage caller ID, per my [previous post](http://yjsoon.com/2011/11/imessage-doesnt-auto-detect-other-partys-imessage-capability).

* Open AppleScript Editor, paste the code in, save, __back up your address book__ (File → Export Address Book Archive), run.

♦ CodeRunner →

CodeRunner is a Mac app that lets you:

> Edit and run code in AppleScript, C, C++, Java, JavaScript (Node.js), Objective-C, Perl, PHP, Python, Ruby, Shell or any other language you might have installed on your system.

This could be really useful for programming teachers — one of the big headaches we always have in the first lesson was making sure things were set up properly. There was a time we tried teaching C++, and found out that the computers’ permission settings disallowed running of _any_ shell programs, so we sang songs and dreamed of correcting missing semi-colons. Ah, fun times.

♦ Shell script and Alfred extension to toggle proxy in Lion

My stupid ISP occasionally (and inconsistently) fails to load some sites unless I’m on their web proxy. As a result, I constantly have to do the network proxy toggling dance on my Mac (System Preferences → Network → Advanced → Proxies → checkbox).

Turns out this can be done with a [script](http://forums.macrumors.com/showthread.php?t=959704). In Lion, though, Apple’s renamed “AirPort” to “Wi-Fi”, so I’ve updated the scripts from the linked post:

* To enable the proxy, use `networksetup -setwebproxystate wi-fi on`
* To disable, use `networksetup -setwebproxystate wi-fi off`

Here’s a (very fragile) shell script to toggle your proxy, depending on whether it’s on:


e=$(networksetup -getwebproxy wi-fi | grep "No")

if [ -n "$e" ]; then
  echo "Turning on proxy"
  networksetup -setwebproxystate wi-fi on
  echo "Turning off proxy"
  networksetup -setwebproxystate wi-fi off

I’ve also packaged it as an extension for the extraordinarily useful launcher [Alfred](http://alfredapp.com), so I can just hit cmd-space, type in “proxy”, and it’ll toggle between the two states (with a handy Growl notification telling me what it just did). You can download it here.

Some notes:

* For all these scripts to work, you must already have the proxy set up in your Network Preferences.
* I believe these scripts only work on Lion — for Snow Leopard and before, try changing `wi-fi` to `airport`. Sorry, I don’t have any machines on 10.6 to test on!
* The script is fragile because it’ll break the moment Apple changes the output of `networksetup`. [Let me know](http://yjsoon.com/contact) if this happens, and I’ll try and fix it.

♦ Connecting to UOB Internet Banking with Lion →

Thanks to a nonsense Java applet, UOB’s Internet Banking service doesn’t work with _any_ browser on Mac OS X Lion, even with the additional Java software update installed. Java! So secure you can’t access your own damn account!

Luckily, one Justin Lee found a way to connect, thanks to an exceptionally half-hearted compatibility fix by UOB: just tell the UOB website that you’re on an iPhone, and it’ll happily let you in without its Java applet “security” goodness.

His suggested method is to use Firefox and download a plugin called User Agent Switcher, but you can also accomplish the same thing by [enabling Safari’s Developer menu from its preferences](http://www.apple.com/safari/features.html#developer), and choosing Develop → User Agent → Safari iOS.

(I vaguely recall another bank site having the same issue — Citibank? I’ll update this post if the fix works there, too.) _[Update, 15 Aug: nope, all the other banks I use — Citibank, DBS and HSBC — work fine.]_

♦ Making MacVim open files in vertical splits

When coding, I like to use [MacVim](http://code.google.com/p/macvim/) with PeepCode’s little [PeepOpen app](http://peepcode.com/products/peepopen) as my auto-completing filename browser. It’s like TextMate’s Cmd-T “Go to file” functionality, and it’s awfully fast and convenient.

One problem I’ve had, however, is that MacVim’s preferences (as at snapshot 61)* only allow you to open files from other applications (in this case, PeepOpen) in the same window, a new tab, or in a horizontal split. Here’s how you set MacVim to open files in vertical splits — open a terminal, and enter:

defaults write org.vim.MacVim MMVerticalSplit YES

While I’m at it, here’s another useful one: [this link](http://webexpose.org/2008/10/13/open-macvim-tabs-from-command-line/comment-page-1/#comment-95424) shows you how to edit `mvim`, the command line script to open MacVim, so that it doesn’t open new windows when called multiple times from the command line.

* There’s a [pull request](https://github.com/alloy/macvim/pull/29) to make MacVim’s “open files” preference a bit more sensible: in a new window, in the current window, in tabs, in horizontal splits or in vertical splits. Hopefully this makes it into future builds, because seriously, who the hell understands “open files and set the arglist” as “open in current buffer”?