Wednesday, July 15, 2009

Firefox 3.5's Three-Finger Swipes

In addition to the previous "twist" gestures which are disabled by default, Firefox 3.5 also ships with default enabled multi-touch swipe inputs:
  • Three-finger swipe up: Home key (top of the page)
  • Three-finger swipe down: End key (bottom of the page)
  • Three-finger swipe left: Browse back
  • Three-finger swipe right: Browse forward
These can be edited by entering about:config in the address bar. Enter swipe in the filter box.

Use web proxy auto-discovery in Safari

Unlike most browsers, Safari doesn't have a setting to use WPAD (web proxy auto-discovery) in OS X. However, there is a way to ask Safari to automatically detect the network's proxy settings, but only if your network administrator has configured WPAD on your network.

This auto-detect feature works through DNS. The browser looks for a host named "wpad" and if it exists, loads its settings by accessing a file named "wpad.dat" via HTTP. To use DNS-based WPAD with Safari on OS X, follow these steps:
  • In Safari, choose Safari » Preferences
  • Click on the Advanced icon
  • Click on the Proxies » Change Settings button
  • In the Configure Proxies dropdown menu, select Using A PAC File
  • In the PAC File URL field, enter http://wpad/wpad.dat
  • Click on OK
  • Click on Apply
Again, this is only helpful if your network administrator has set up a proxy to be auto-configured. If you're on a network that doesn't have such a setup, Safari will still work but much, much slower. To find out if your network supports proxy auto-detection, visit http://wpad/wpad.dat in your web browser. If your network supports WPAD, then your browser will download the file "wpad.dat" (which you can just delete). If it's not supported, you'll get an error message.

Tuesday, July 7, 2009

Remove Safari history files on logout via shell script

If you'd like to remove your Safari history files when you log out, first create the following shell script:
#!/bin/bash

# Point this at your user folder.
useroot=/Users/your_user

# Clear Safari History (except for bookmarks).
rm -f $useroot/Library/Safari/Downloads.plist $useroot/Library/Safari/History.plist
rm -f $useroot/Library/Safari/HistoryIndex.sk $useroot/Library/Safari/TopSites.plist
rm -f $useroot/Library/Safari/WebpageIcons.db $useroot/Library/Safari/LastSession.plist

# Add any additional clean-up here.
Save the script somewhere, make it executable, and because it runs as root, make sure it is protected from modification. Then copy and paste this command into Terminal, modifying it to point to wherever you put the above script:

sudo defaults write com.apple.loginwindow LogoutHook "/Users/your_user/scripts/privacy.sh"

To be complete, you should also visit Safari's Preferences, open the AutoFill tab, and clear all of the checkmarks (Safari then won't remember passwords and forms).

Make SMB shares appear in Devices section of Finder sidebar

It was driving me nuts that SMB shares from my Windows server would not reappear under DEVICES in the sidebar. However, I then figured out that I can do this:
  1. Open System Preferences » Network
  2. Click the network interface you use for the shares
  3. Click on the Advanced button at lower right
  4. Click on WINS tab, and manually enter the workgroup name of the server
  5. Click the '+' under the WINS Servers list
  6. Enter the IP of the server (you are using static IP on your server, right?)
  7. Click OK, Apply, etc. until you're done
The next time I dragged a mounted share to Devices, it then showed up there automatically after the next unmount/mount. My shares seem to mount much faster now, as well. Now if only I could find a way to increase the transfer speed...sigh.

Mac OS X 10.5: Wake a sleeping Mac with via Automator

I have a Mac mini in my living room hooked up to my TV. I wanted to be able to control the mini from my iMac in my office. Using Screen Sharing built into Leopard, it's a simple click of the mouse to do this. With a little Automator love, I created a simple workflow that turns the Screen Sharing step into a click of an icon in the dock.

However, even with the power efficiency of the 2009 Mac mini, I don't want to leave it on 24/7. After searching through several solutions that used Python and shell scripting (neither of which I know or could make work), I found this nifty this nifty Applescript from Mark Muir that I adapted to solve my problem. Here's my modified code:
(*
Script adapted from Wake on WAN - by Mark Muir (2008-04-01)
http://forums.dealmac.com/read.php?4,2751523
*)

property MAC_address : "00:25:4b:9f:63:c8"
property WAN_IP_address : "255.255.255.255"

on run
set command to "/usr/bin/php -r " & quoted form of ("$mac = " & quoted form of MAC_address & "; $ip = " & quoted form of WAN_IP_address & "; " & "
$mac_bytes = explode(\":\", $mac);
$mac_addr = \"\";
for ($i=0; $i<6; $i++)
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = \"\";
for ($i=0; $i<6; $i++) /*6x 0xFF*/
$packet .= chr(255);
for ($i=0; $i<16; $i++) /*16x MAC address*/
$packet .= $mac_addr;

$port = 9;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port);
socket_close($sock);
")
do shell script command
end run
You'll need to replace the MAC_address property with the MAC address (found in the Networking System Preferences panel) of the machine you'd like to wake. I then wrapped this script in a simple Automator application to make it a true one-click operation. You can read all the details, and download a copy of the Automator application, in this entry in my blog.

I've mirrored the Automator application here on Mac OS X Hints, in case the original post ever goes away. While I haven't tested this one, I'm pretty sure you could replace the full script shown above with a call to the free Wakeonlan perl script, which was described in this older hint.

Wednesday, July 1, 2009

SSH’ing Into Your Mac

I use SSH a lot, it stands for Secure Shell and its main purpose is to connect to other computers, or servers, over a secure connection which you can use to manage the remote computer. For a general overview I recommend reading this Wikipedia article. For this article you do need to be a little tech savvy with Terminal, but if you are way from your computer, or you want to manage another computer this is a very useful technique.

The first step, which you must do, is enable this process in your Firewall. Took me ages to work out while I couldn’t do this on my own Mac. Go to System Preferences > Sharing and check Remote Login. This will open port 22 on your computer and allow SSH to be active.


This should be done on the computer you want to log into. For the purpose of this tutorial you can do it on your own computer, remember to switch it off when you have finished for security purposes. Under the Green icon there will be an address. This combines your ISP Internet address, which is given to you by your ISP, in my case it is part of my Uni address, this will be unique to you. For example it will be a unique identifier, such as a MAC address or account name, on your ISP network, it will then be preceded by your ISP web address. For the most part you don’t need to understand how this address is built. You just need to know what it is. The first part of the address is the user name, for the purpose of most maintenance a normal account will suffice, if you want to do some really high level stuff an administrators account can be used.

You can now log into the remote (or your Mac). Open terminal and type:

ssh user@ISP.address.com

This will start the connection process. If it immediately says connection refused make sure you have enabled SSH as mentioned above. If it says couldn’t connect on port XXX, add the following.

shh -p22 user@ISP.address.com

This will force your SSH connection to run on port 22, instead of a different port. If you, or someone else, has used SSH before it may have been bound to a different port. This will correct this problem.

The first login will ask you to accept and RSA key. This is a method to make sure the two computer are who they say they are. Since you know this accept the key by typing yes and hitting return. This is a security method to keep the connection secure, more information about this process can be found here.

The very final step is to type the password which belongs to the user name. This is the remote Mac’s login password, not your own, my friend who I tried to teach this concept too, didn’t grasp this step for a long while and confusion ensured. Once you have done this, the connection will be secured and you can happily run commands on their computer.

At this point you can run any Terminal command, which is useful to sort out problems with file and folder errors and problems relating to settings. You can also use it to monitor the health of the remote computer by running a process such as ‘top’. The Terminal window, at this point, is exactly the same as one you would use on your own computer. It just happens that the result run on a different computer and are forwarded to you.

When you have finished your session, type exit and the SSH session will finish.

Although this is a tech savvy process and solutions such as screen sharing are more useful to people who do not know how to use Terminal, it is a great technique to learn. You can use it on any Mac, Linux or Unix computer, this method is exactly the same. It is also very low bandwidth, with screen sharing your are sending a lot of data, this technique sends text. Text has a very low data rate, as a result can run on a dial up connection. This sort of process can be used to administer a server over a home network, or to make sure a remote Mac (such as your Grandparents) is still operating fine.

There is a lot more topics on how to use SSH on your Mac. I recommend search the internet for how to find out more, if you are interested on using this technique more.