instructions

You are currently browsing the archive for the instructions category.

Quick Tip for a longer MacBook Pro battery life (with LED backlit screens): Make a Hot Corner for turning off the screen and use it whenever you’re not actually looking at the screen. (System Preferences -> Desktop & Screen Saver -> Hot Corners… [button])MacBook Sleep Display Hot Corner

If you’re like me and do multiple things while working with your MacBook, there are times when you’re not actually looking at the screen.  Quickly swipe your mouse to the Hot Corner you’ve setup for Sleep Display and you’ll reap instant power savings with very little cost in terms of downtime/wake time.

Fluorescent tube backlit screens unfortunately have a warm-up/cool-down time that causes the screen to appear dark when first lit and slowly increase in brightness as the backlighting tube warms up.  LED backlit screens brighten instantly to their preset level, so take advantage of it.

Instead of installing Flip4Mac you can use VLC to watch streaming videos, particularly Windows Media (wmv) streams on Mac.

Here’s how:

Download VLC for Mac OS X here. Install and Launch VLC Player.

A Windows Media stream that cannot be played in Firefox will only show a lego brick and a blank area.

WMV Plugin needed Firefox Mac

To find the media stream in Firefox, go to Tools -> Page Info (Cmd + I).

Firefox Page Info

On the Page Info pop-up window, click on the Media tab.

firefox_wmv_media_stream

One of media items in the list will use a different protocol than http, in this case, mms with the Type as Embed.  In the Location information just below the list you’ll see the mms media stream Internet address. In this case mms://live.france24.com/election-en.wsx.  Highlight this address with your mouse and Cmd + C to copy it.

Now it’s time to open that Windows Media stream in VLC Player. Click on File and Open Network.

VLC Open Network

Paste the Windows Media stream that you copied earlier into Media Resource Locator field. Then click on HTTP/FTP/MMS/RTSP radio button on the left hand side of the Open Source window.

Open WMV Stream in VLC

Click OK. VLC will begin loading the stream and will play the WMV stream shortly.

VLC Playing WMV media stream on Mac

Enjoy your coverage of Obama defeating John McCain on France 24 live media stream.

To download old or previous versions of Firefox, such as 3.0.2 or earlier, try this (official Mozilla) address: http://releases.mozilla.org/pub/mozilla.org/firefox/releases/

This site makes available for download Firefox 2(.0.0.6) up to the latest official release (3.0.3 as of Oct 2008) and nightly builds which contain fixes to bugs up until the previous night.

Firefox Old Versions at Mozilla.org

I’m currently having a problem with Firefox 3.0.3 not showing/processing stylesheets (CSS) from web pages upon first load, requiring multiple reloads pressing Cmd + R (Ctrl + R for you Windows folks) in order for the page to be displayed properly.  Otherwise, the page loads with text only, hyper-ugly, 1994 style web page

To get back disk space on your Time Machine Backup drive you can delete or remove backed up items from Time Machine permanently.

First, go into Time Machine by clicking on the clock arrow icon in the Dock (top right hand corner beside your clock).

How to enter Time Machine from Dock

Then in Finder (with all the files and folders listed), click and highlight the item that you want to remove from your Time Machine backups.

Next, click on the Gear icon at the top center of the window.

Finder Gear Button

And choose Delete All Backups of …

Time Machine will then proceed to remove all traces of the item from your backups.  It’s a good idea to exclude this item from Time Machine before you perform this removal.  If you don’t, the next time Time Machine runs, you’ll end up with this item again in your backups.  Within the Preferences for Time Machine, click on the Options button.  That will open a window with a list of “Do not back up” items.  Clicking the Plus (+) button allows you to select files or folders that you wish to exclude from Time Machine.

When connecting to a remote mysql server, the login/user must have rights to connect to the mysql server from outside of the local server, i.e. localhost. You need to edit the user record within the mysql.user table or add a new record for this user, giving it access to connect to the mysql server from a host other than localhost.

Login to the mysql server add run the following command:
grant all privileges on *.* to 'user'@'192.168.25.1' identified by 'password' with GRANT OPTION;
Replace “user” and “password” and “192.168.25.1″ with your mysql username, password, and the IP address of your computer that you’re connecting (to the mysql server) from.

Remember that your mysql server must also allow connections from remote hosts.

By default mysql does not allow connects to itself from any host besides localhost, for security reasons.

When you get an error “Can’t connect to mysql server on [remote server]” when trying to connect to the remote SQL server via the mysql command line tool, log into the server running the mysql server and edit the /etc/mysql/my.cnf config file.

In particular, comment out the following line:
bind-address           = 127.0.0.1
This allows for connections from any host.

Next, update the mysql user to allow it access from a host other than ‘localhost’.

To have Apple Front Row show and play videos inside of an iso file, first mount the iso file then make links to the video files inside of the iso, within your Movies folder. This can be useful for example when you have a season of television episodes of House MD in a single ISO disc image somewhere on your Mac.

step 1: mount iso file

First mount the iso file by double clicking on it (within Finder, on your desktop, wherever it may be). The ISO file will be mounted like a drive and will show up within Finder under Devices and look like this:

In my case the iso file disc image was named 20071107_170514 when it was created. Your mounted iso volume will be named differently.

step 2: link to video files in iso

Create symbolic links to the video files within your Movies folder using the Terminal. Afterwards the videos will show up in Front Row like any other video or movie and you don’t have to copy the files out, saving disk space.

Before that, I’m going to create a folder within ~/Movies with a descriptive name (since 20071107_170514 is meaningless to me). In the Terminal window I would enter:
mkdir ~/Movies/HouseSeason4

Now create symbolic links to the videos with the the “ln” program:
ln -s /Volumes/20071107_170514/*.avi ~/Movies/HouseSeason4

ln is the link program
-s tells the link program to make symbolic links (like detour signs to real files)
/Volumes/20071107_170514 is the mounted iso volume. Change 20071107_170514 to whatever your iso volume is named.
*.avi In my case the video files were AVI files and I wanted all of them (*) to be linked. Change this to whatever format the videos happen to be for you, for example: *.mpg *.mkv
~/Movies/HouseSeason4 is the directory where the videos will appear in Front Row. Since Apple Front Row automatically searches through your Movies folder for videos, making a subdirectory underneath Movies is an ideal spot. These symbolic links will appear like any other video file and Front Row will browse and play these files as if they were actually located in your Movies folder.

step 3: Watch iso videos in Front Row

Start Front Row by hitting ⌘+⎋ (Command Key and Escape) or hitting the Menu button on your Apple remote.

Go into the Movies folder and you should see the folder you created in Step 2. Go into that folder and you should see the video files that were inside the iso disc image file. From here you should be able to play the video files that are inside the iso, without having to copy the files out to your Movies folder and taking up twice the disk space.

Notes

Any volumes that you mount will be unmounted automatically when you reboot. Since the symbolic links within your Movies folder aren’t the actual video files themselves, they need the mounted iso volume to work. After rebooting, remember to remount your iso disc image by double clicking on it before looking for videos inside it within Front Row.

How to fix Slow Web Browsing and Slow Internet in Leopard (10.5.x)

Symptoms

  • Web pages load slowly in Safari or Firefox in Leopard.
  • Web sites won’t load, only load partially, stop loading after a few hours.
  • Slow DNS (domain name) lookup in Leopard. First load of web site is slow with “looking up domain” in browser status bar.
  • Once website is loaded, browsing to that site is fast.
  • AirPort wireless strength drops, then Internet connection is lost (see related post).
  • Email programs are slow in connecting to servers.
  • SSH sessions are slow to connect to remote servers.

Possible Causes of Slow Internet under Leopard

  • Your ISP’s DNS servers are (sometimes) slow to respond due to high traffic.
  • Firefox, Camino, Safari is requesting domain name lookups in IPv6 format (2001:db8::1428:57ab), but your DSL router/cable modem answers with IPv4 addresses (192.0.2.235) (references: mozillazine.org, mozilla.org bug, arstechnica.com). Safari may not be affected by this as WebKit is said to use IPv4 domain lookups first, then uses IPv6 if IPv4 fails.
  • Your router, acting as a DNS Proxy, doesn’t recognize nor forward IPv6 domain name lookup requests.
  • Leopard is now requesting SRV (service) records for domain name lookups. Your router does not recognize nor forward to SRV requests.
  • Your ISP’s DNS servers don’t recognize or doesn’t respond to SRV queries or respond with NXDOMAIN.
  • [Added 080618] Poor wireless router performance in general (references: entropy.ch). To test this, try connecting directly to your DSL router/modem if you are using an intermediate router such as an Apple AirPort Base Station, or NetGear/Linksys wireless router and seeing if web and internet speeds increase.

Fixes/Solutions/Workarounds

Details

After upgrading to Leopard, plenty of Mac OS X users have complained of “slow internet” when browsing the web, yet Windows PCs or Macs with Tiger (10.4) on the same network are much faster.

DNS Lookups

A domain name lookup or DNS lookup is done every time you visit a web page, say “apple.com”, as you’re actually visiting “17.149.160.49″. A DNS Resolver on your computer sends a request to a DNS Server that handles this lookup or translation from names (easy to remember) to numbers (hard to remember). Once your browser has this numerical IP address it can start loading the web pages at that server location.

Domain Name System Lookups in Leopard

With Leopard, a major change occurred in DNS lookups. Any program in Leopard that can use version 6 IP addresses (IPv6 explained below) will send out a new type of DNS lookup request - the SRV Record. In Tiger and previous OS X versions, DNS lookups were A record requests.

SRV records are new (sadly, 8 years old is new in the DNS world), provide more information than A records, but have terrible support in terms of hardware (your DSL router or cable modem) and DNS servers that answer with SRV information. For every SRV request that Leopard sends it must wait for a valid reply. If the request fails, Leopard must try again. If it fails again, Leopard will finally ask for an A record. This is one reason why Mac users are experiencing slow Internet on new Macs with Leopard or after upgrading to Leopard from Tiger.

Domain Name Lookup Chain

Diagnosing slow Internet problems under Leopard is difficult due to the many different slowdowns that can occur along the domain name lookup chain when connecting to the Internet in OS X. For an application like Firefox or Safari to find a domain name, this is roughly what happens:

  1. Firefox/Safari is asked to load a web page at a domain name (example: “apple.com”).
  2. Browser starts work on getting an IP address for that domain (a domain name lookup).
  3. Browser checks for recently translated domain names in its own internal “cache” and thus already has the IP address.
  4. If “apple.com” is not found in cache, Firefox/Safari then asks Directory Services (an OS X program that does DNS lookups) for the answer.
  5. Directory Services (DS) searches for the domain in its own DS cache (view the DS cache using Terminal: dscacheutil -cachedump -entries).
  6. If domain is not found in cache, DS checks flat (text) files such as /etc/hosts for the domain name (see the file using Terminal: cat /etc/hosts).
  7. If domain is still not found then DS sends a domain name lookup request to the first DNS server listed for your AirPort wireless card or your Ethernet card (your network interfaces). The first (and usually only) DNS server is often your router (often listed as 192.168.1.1 in System Preferences => Network => Advanced => DNS tab).
  8. If the router doesn’t recognize the name lookup request (SRV/IPv6), the request will be either ignored, returned without result, returned with error. If the router does recognize the DNS request, it checks its own DNS cache for a matching domain lookup.
  9. If domain name is not found in cache, the router forwards the request to the ISP’s DNS server.
  10. If the first ISP DNS server doesn’t respond or doesn’t have the record, the router sends a second lookup request to the next DNS server listed in its configuration. Continue until all DNS servers are exhausted.
  11. When name lookup result is received by router, it saves the result to cache, then forwards the domain name record back to the requesting computer.
  12. Directory Services on Leopard, receives the answer, places it in cache, then returns the results to the requesting application: your browser.
  13. Firefox/Safari receives the DNS record, with IP address, stores it in cache, then starts to retrieve the web page at that location.

(Illustration by Lion Kimbro on Wikipedia - Domain Name Systems article)

Any one of the links in the chain can be a potential source of slow Internet speeds when browsing or retrieving mail, etc. The difficulty lies is finding out where the problem exists and how it can be fix. Compound this complexity with the number of different DSL routers in use in homes, the number of different firmware (software inside the router), number of different ISP DNS servers

Caches

Caches store recent domain name lookup results in order to save time when the domain is requested again. Each time a domain name lookup is made, caches are checked to see if the lookup has occurred recently and if so, use the cache result. If no result is found in cache, the domain name lookup has failed and the DNS lookup request continues down the chain. A domain lookup may fail all the way down the chain until it’s finally resolved with the second or third DNS server listed, taking maybe 15 seconds to finally succeed. But, once domain lookup has been successfully performed, this domain request “answer” is cached all the way back up the chain, for varying amounts of time. Browsers like Safari and Firefox normally cache domain name lookups for 1 minute (30 minutes if you’re Internet Explorer in Vista). Leopard’s Directory Services program caches lookups for one hour (3600 seconds) by default.

Once a successful domain lookup has occurred, web pages from the same site will load very quickly, since the domain and its IP address are known and cached in memory. When the cached domain lookup result expires, the vicious cycle of slow domain lookups restarts. This often leads to the confusing pattern of fast Internet / slow Internet performance that can be seen sporadically throughout a browsing session.

IPv6

IPv6, the new way of addressing all things on the Internet, is important and necessary as we’ll eventually run out of IPv4 addresses (like 17.149.160.49). But part of the issue with slow browsing and slow Internet on Leopard is the combination of how IPv6 is used in Mac OS X and the current state of DSL routers and cable modems.

Whenever a program on Leopard can use IPv6 addressing, such as Firefox, it will request IP addresses for domains in IPv6 and if that fails, Firefox will then try IPv4 domain lookups. The reason this adds to the slow Internet problem is that many routers and DSL or cable modems in peoples homes are not capable of handling/routing IPv6 domain name queries (properly). This can cause repeated, failed DNS queries in IPv6 format, with the requesting application eventually falling back to sending IPv4 domain lookup requests that are successfully answered. The unfortunate problem with this “IPv6 then IPv4″ order of domain lookups is users end up with delays of 5 to 10 seconds “looking up” a domain name, which is not a very long time to wait, but suffering short delays every time you visit a different website can be extremely frustrating.

SRV (Service Record) Requests

Part of the issue may be related to Apple’s decision to follow the Internet Engineering Task Force’s recommendation of using SRV queries instead of “A record” queries when looking up domain names in Leopard.

The problem with Leopard asking for SRV records from DNS servers is that many DNS servers still don’t recognize or respond to SRV type DNS requests, or respond with a non-existent domain (NXDOMAIN) error code. This is not exactly Apple’s fault for asking, it’s actually the fault of DNS server owners who are not updating their servers to the latest standards. Regardless, whenever a program like a web browser requests a DNS record and gets failed responses, or no response at all, the program retries its requests, but only after a certain delay. Each failed SRV request and subsequent retry adds time the user must wait before the browser or application eventually gives up on the SRV requests and tries an old-school basic A record request in an attempt to get the IP address of the domain name. And all DNS servers answer to A record requests, even the old dingy ones not following the latest IETF standards. You, the user, sees this request — no response — retry dance as the browser taking a long time “Looking up domain.com….”, often seen as such on the browser status bar at the bottom left hand corner of the window. Only when the browser or application has received a valid IP address from a domain lookup can it contact the web server and start to download the HTML and display the page.

Timeouts

The delay between lookup retries is important to prevent overloading DNS servers, DNS resolvers (like Directory Services on your Mac) and simply makes sense. It’s similar to walking up to someone’s house and knocking on the door: Normally you wait a few moments for a response before trying again. If you don’t wait, you don’t know whether no one’s home, or whether they’re just taking a few seconds to respond. Continued knocking doesn’t help you. (And perhaps will earn you a stern look if not make you the target of a hissy fit).

Hammering a DNS server with domain lookups without pause is not very productive since the DNS server will simply drop (not answer) requests that it cannot handle within a timely fashion, based on its current load and worse, may get you blocked from the DNS server.

Next we’ll see how we can solve or workaround the issues discussed above that could be slowing down Leopard’s Internet speed.

Solutions

Direct DNS / Better DNS

Update 080606: Leopard 10.5.3 may have changed the order in which DNS Servers are used.

Update 080606: DNS servers entered on a DHCP configured setup are used in reverse order. I.e. the last server entered is the first to be used. If you’ve manually configured a network location, DNS servers are used in the order that you’ve entered them/see them.

New 080606: If you wish to save your current network setup and have the option of returning to it easily, follow the instructions for Creating a New Network Location. Otherwise, follow the instructions immediately below to quickly add new DNS servers.

Add DNS servers to Current Network Configuration

This is the quickest & easiest way to use new DNS servers, which is to simply add them to the DNS tab found in System Preferences => Network => Advanced => click on DNS tab.

Click on the + sign at the bottom left hand corner near IPv6 or IPv6 addresses and type in the addresses of the DNS servers you wish, in reverse priority order. (Recommended: OpenDNS servers at 208.67.220.220 and 208.67.222.222). I.e. the server that you want to use first, enter it last. Afterwards, click Ok. Then in the Network pane, click Apply to make your changes active. If you’re using an AirPort wireless connection, wait a few moments for the connection to be re-established

Creating a New Network Location

The advantage of creating a new network location is the ease of which you can move back and forth between different network setups. By creating and using a new network location, you can always revert your changes by simply selecting your original (Automatic) network location from the Location drop down list.

In Leopard, open System Preferences => Network => click the Advanced button (bottom right corner)


Click TCP/IP tab (top left).
Write down on a piece of paper (or in TextEdit) the IPv4 Address, Subnet Mask (255.255.255.0), Router, and Configure IPv6 setting. Click Cancel.

Find the Location drop down at top of the Network preferences pane. Click it and choose Edit Locations.


Highlight “Automatic” if not already
Click the Gear icon on the bottom center, choose Duplicate Location


Choose a name, I used “Home”.
Change the Location drop down box by clicking on “Automatic” and then switch it to “Home” (or the name you chose in the last step)
You’ll see the following:


Select Airport on the left (or Ethernet if you’re not using a wireless connection).
Click Advanced at the bottom right.
Click on the TCP/IP tab-button.
Change the Configure IPv4 drop down box to “Manually”.
Here’s where you use the values you saved in Step 2. Fill out IPv4 address, subnet mask, router, configure IPv6 settings. Do not click OK, instead click on DNS near the top.
Click the + button, bottom left hand corner. This creates a blue outline under DNS Servers on the left half of this window.

Enter in the DNS server of your choice. I recommend OpenDNS at 208.67.222.222. (Don’t include a period at the end). Add a second OpenDNS server by clicking again on the + button and entering 208.67.220.220. These DNS servers will automatically redirect you to the closest / best server for you, regardless of whether you’re in France (like me) or in North America. Click OK. You should be returned to the Network preferences pane and see something like the following:

At this point you’ve created a new Location called “Home”, having setup AirPort or Ethernet with the correct settings and “Services” (i.e. DNS), but none of these changes have been made active. Let’s make a backup of the configuration file that will be updated before you apply your changes. In Finder, click on the hard disk icon at the top left corner (usually Macintosh HD), then navigate to this directory: /Library/Preferences/SystemConfiguration and find this file: preferences.plist. Simply copy the file to your Documents folder or to a spot of your choice. If you have to rollback the applied changes, you can copy this file back to the above location. If you’re using Time Machine, this file should be backed up already. Now you know where this file is, so replacing it with a Time Machine version should be straightforward.

Before we make our changes effective, we’re going to check how DNS requests are handled now, before the changes, and after to make sure we’ve changed our Network Settings properly.

Leave the Network window open as is and open up a Terminal window. We’re going to be using the tcpdump program to listen to DNS traffic between your computer and your DNS server.

Type this command and hit Enter: sudo tcpdump -i en1 -s 128 port 53

(If you’re using Ethernet with a cable, use en0 instead of en1, which is the AirPort wireless interface).

Supply your password when asked to do so.

You should see something like the following:

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en1, link-type EN10MB (Ethernet), capture size 96 bytes

tcpdump should now be running.

Open up another Terminal window and type the following command: curl http://www.csu.edu

This uses the curl program to read the web page located at www.csu.edu.

Going back to your tcpdump window you should see something similar to this:

00:31:37.026520 IP 192.168.1.132.56645 > WANADOO-D310.domain: 19279+ SRV? _http._tcp.www.csu.edu. (40)
00:31:37.029352 IP WANADOO-D310.domain > 192.168.1.132.56645: 19279* 0/0/0 (40)
00:31:37.029849 IP 192.168.1.132.56646 > WANADOO-D310.domain: 49549+ SRV? _http._tcp.www.csu.edu. (40)
00:31:37.032657 IP WANADOO-D310.domain > 192.168.1.132.56646: 49549* 0/0/0 (40)
00:31:37.034345 IP 192.168.1.132.56647 > WANADOO-D310.domain: 46004+ A? www.csu.edu. (29)
00:31:37.279043 IP WANADOO-D310.domain > 192.168.1.132.56647: 46004 1/0/0 A www.csu.edu (45)

Notice 192.168.1.132. That’s me, or really, my MacBook Pro’s AirPort wireless card. Then there’s a greater than sign (>) showing the direction of DNS traffic. WANADOO-D310 is my DNS server, which is actually the DSL modem/router, a.k.a. 192.168.1.1, which is passing domain name lookups to the real DNS servers at my Internet Service Provider (WANADOO, yeah I know goofy name). Remember the network settings we wrote down before starting all this? You’ll notice that the DNS server is 192.168.1.1.

OK, we’ve got a baseline of what our Mac is doing when looking up domain names, let’s apply our new network location “Home” that we created and see the difference.

Back on the Network preference pane, notice the Apply button on the bottom right hand corner. Once you apply your changes, your Mac will begin using the new Location you’ve created.

Take the plunge and click on Apply.

For AirPort wireless connections, you may have to click the Turn AirPort Off button, wait fifteen seconds, then click Turn AirPort On again in order for the new DNS settings to be used.

Going back to the Terminal window where we executed the curl command, and with our changes set, let’s execute another: curl http://www.unc.edu

Results will look like the following:

00:32:33.562589 IP 192.168.1.132.56663 > resolver1.opendns.com.domain: 39356+ SRV? _http._tcp.www.unc.edu. (40)
00:32:33.767237 IP resolver1.opendns.com.domain > 192.168.1.132.56663: 39356 NXDomain 0/0/0 (40)
00:32:33.767856 IP 192.168.1.132.56664 > resolver1.opendns.com.domain: 62833+ SRV? _http._tcp.www.unc.edu. (40)
00:32:33.809161 IP resolver1.opendns.com.domain > 192.168.1.132.56664: 62833 NXDomain 0/0/0 (40)
00:32:33.811130 IP 192.168.1.132.56665 > resolver1.opendns.com.domain: 45293+ A? www.unc.edu. (29)
00:32:33.853070 IP resolver1.opendns.com.domain > 192.168.1.132.56665: 45293 1/0/0 A www.unc.edu (45)

Notice what’s changed? WANADOO-D310.doman has changed to resolver1.opendns.com.domain. This is OpenDNS’ name for the DNS server we started using, 208.67.222.222, which we entered as our DNS for the “Home” location. Also, note how instead of just getting a 0/0/0 response, we’re getting NXDOMAIN 0/0/0? That’s at least the DNS server responding saying: that domain doesn’t exist (not exactly true, since the domain does exist, but it just doesn’t have an SRV record), rather than the DNS server sending back nothing, not even an error code. Also, notice how our Mac tried twice on asking for SRV records, and the DNS server responded twice, that no record exists for that domain, and then finally our Mac asks for an A record (A?) and gets one answer record back (1/0/0 A ww.unc.edu).

If you want to see a domain that actually has a proper SRV record, try this in the curl terminal window: curl http://s3.amazonaws.com

Results should be something like this:

09:36:56.440037 IP 192.168.1.132.61010 > resolver1.opendns.com.domain: 34536+ SRV? _http._tcp.s3.amazonaws.com. (45)
09:36:56.671881 IP resolver1.opendns.com.domain > 192.168.1.132.61010: 34536 2/0/0 CNAME s3-directional-w.amazonaws.com., (97)
09:36:56.673894 IP 192.168.1.132.61011 > resolver1.opendns.com.domain: 18143+ A? s3.amazonaws.com. (34)
09:36:56.715913 IP resolver1.opendns.com.domain > 192.168.1.132.61011: 18143 2/0/0 CNAME s3-1.amazonaws.com., A s3.amazonaws.com (69)
09:36:57.263186 IP 192.168.1.132.61012 > resolver1.opendns.com.domain: 32069+ PTR? 171.206.21.72.in-addr.arpa. (44)
09:36:57.306060 IP resolver1.opendns.com.domain > 192.168.1.132.61012: 32069 1/0/0 PTR s3.amazonaws.com. (74)

Here we’re getting 2 answer records (the “2″ in 2/0/0) on the SRV requests, which are CNAME records, first being s3-directional-w.amazonaws.com, second being s3-1.amazonaws.com. CNAME records are “nickname” records, which point to true name, or A Record. Right after that our Mac asks for an A record on the first CNAME that was returned to us (s3-directional-w.amazonaws.com) to get back the actual IP address (72.21.207.246), which you can verify by using the dig program.

This fix alone has made my Internet connection much faster since my ISP’s DNS servers were sometimes under heavy load and slow to respond to DNS queries. Most of the time, I’d get name requests done in 200-400ms. Not noticeably slow. But, on occasion domain name lookups would timeout after 7 seconds, multiple times, resulting in up to 21 seconds of waiting for a single name lookup request to occur. This is excruciatingly long when I often open up multiple different websites one right after another when starting a browsing session. To make matters worse, many websites are getting into the practice of placing different parts of the web page on different domain names. Let’s take CNN.com for example. To load this single page of President Obama… oh, I mean senator Obama, waving to the crowd, tcpdump showed name lookups for the following domains:

  1. www.cnn.com
  2. edition.cnn.com
  3. i.cdn.turner.com
  4. i2.cdn.turner.com
  5. svcs.cnn.com
  6. ads.cnn.com
  7. i.cnn.net
  8. ad.doubleclick.net
  9. metrics.cnn.com
  10. m1.2mdn.net

One Page. Ten domains. Ten DNS lookups. Ouch. And I’m not including PTR/Reverse Lookups for each domain, making it really 20 DNS queries.

And does anyone wonder why problematic DNS performance in Leopard would slow web browsing to a crawl?

Disable IPv6 DNS Lookups

Firefox and Camino by default do DNS lookups using IPv6 addresses by default, reverting to IPv4 if that fails. This can be a problem when the router that we are using to connect to the Internet doesn’t work with IPv6 DNS requests properly, if at all.

To disable IPv6 DNS lookups in Firefox and Camino, type the following into the browser address bar:
about:config
If you see a large “Be Careful” warning, simply click on “I understand and I wish to continue”. Next, you will see a long list of Preference Name, Status, Type and Value columns. Above all that is a bar in which you can filter which preferences to view. In the Filter bar type: ipv6
You should see something like the following:

To change the value for this preference simply double-click the name “network.dns.disableIPv6″. The value you want is “true”, which means that IPv6 DNS requests are disabled. If this value is already “true”, don’t double-click this preference.

To make the preference change active, close the browser and Quit Firefox completely (Apple Key + Q), then restart Firefox. You may have to repeat this Quitting and Restarting to have the change take effect.

After making this change, Firefox (or Camino if that’s what you’re using) will use IPv4 only when performing DNS requests.

Update DNS Servers on Router

If you have access to your router’s administration web page, you may be able to set its DNS servers manually, avoiding the buggy DNS servers located at your ISP. Refer the manual that came with your router, or speak with your service provider about how to access the router’s administration page. Often this page can be accessed at http://192.168.1.1, so simply type that address into your browser’s address bar and press Enter. With any luck you’ll have access to the Administration login page. Many router administration sites don’t have passwords, don’t have usernames, or use very simple standard passwords such as “admin”, leaving it up to the owner to change it to something more secure. Visit the router manufacturer’s web site for more information about accessing the administration features of the router.

Keep in mind that updating the router’s DNS servers will not avoid problems you may be encountering with the router’s poor DNS Proxying/Forwarding support. If your router can’t handle IPv6 or SRV requests coming from your Mac, these DNS requests will stop here at the router and will not be forwarded onto the new DNS servers you’ve just specified, making this fix completely ineffective. DNS requests that your router cannot understand will likely be ignored or returned without answer results. DNS Proxy/Forwarding issues are discussed further in the next section.

Update Router Firmware

For those who need to continue making DNS requests through their router, rather than directly against DNS servers, due to VPN or tunneling requirements, your fix may lie in upgrading your router’s firmware. Routers are in effect “the” DNS server for the majority of home broadband Internet connections since it acts as the DNS Proxy, taking domain name lookup requests from your computer, passes them to the ISP’s DNS servers for resolution, receives the results, and finally passes the name lookup results back to your Mac, all transparently in the background. This is why your DNS server address is the same as your “Gateway” which is a fancy name for your router, since all traffic passes through this “gate” of sorts. Thus the Gateway address is often 192.168.1.1, which in turn is also the address of the DNS server for the “Automatic” network Location in Leopard.

Be aware that DNS Proxying is a common failure point in the domain name resolution chain. If the router is not compliant with the latest Internet Task Force standards, it may not know what to do with SRV requests (which Leopard now uses) and may simply ignore them, return empty results, or return NXDOMAIN (non-existent) errors. Again, a firmware update may bring your router up to the latest standards for DNS servers.

If the router is a DSL Cable modem/router, contact your ISP and ask whether there is updated firmware for the model of router you’re using. If you’re more of a do-it-yourself person you can attempt to find the manufacturer of the router/modem and find the latest firmware from their website, if available. Disclaimer: updating the firmware of your router with the wrong firmware, or not completing the firmware update due to power loss, will render your router useless. Do not attempt to update the firmware if you are not confident of what you’re doing.

New Information


Update 080606: As per a discussion on Macosxhints forums, Apple may have changed the order in which DNS servers are used. In the screenshot, the listed DNS servers are used in the order they are seen, under Leopard 10.5.2. This is true for a manually configured Network Location. In 10.5.3, users are seeing the opposite order, i.e. In a DCHP configured Network Location (automatically done by your DSL router and ISP), the DNS servers listed are used in reverse order. (Bottom server is used first, then moves up the list as needed). Thus adding a new Network Location to use a given DNS server would be unnecessary.

Update 080614: Airport Wireless Connection Drops - This is a common problem for Leopard users after upgrading to 10.5.2. This isn’t exactly a slow Internet problem, but rather, a “no Internet” problem. See this related post on wireless problems on Apple AirPort connections.

The Beginning

This is not the end, but rather, the beginning of an article that I hope will continue to grow in scope to cover more problems and offer more solutions to slow Internet problems in Leopard. Please leave a comment if you’re experiencing a problem not discussed here and we’ll get working on diagnosing the issue and searching for a cure.

If you’re having troubles implementing a fix listed above, leave a comment and I’ll try to expand on the topic or reword it so that it is understandable to you and to everyone else I’ve confused.

Keep in the Loop

- Ben

Need to debug a slow Internet connection in OS X? Or simply have a desire to watch incoming and outgoing DNS (domain name service) queries in Leopard? Then tcpdump is your friend.

Open a terminal window and use the following command:

sudo tcpdump -i en1 -s 128 port 53

-i Sets which interface to listen to. en1 for me is the AirPort wifi card. en0 would be the ethernet card.
-s sets the number of bytes to “sniff” or “snarf” per call that goes through this interface. 128 gives us a bit better coverage than the default 68 bytes. If you find that tcpdump requests are showing up simply as [|domain], that means that the request is longer than 68 bytes and is truncated. To prevent truncation, increase -s.
port 53 is simply the network port for DNS communcation

Learn more about tcpdump at developer.apple.com

To play divx videos or movies in QuickTime / Front Row on Mac OS X, you need to install a divx codec. If you open an .avi file and see only black, you likely don’t have a divx codec installed.

Download a free divx codec for Mac here then following these walkthrough instructions on how to play divx videos on Mac.

Say you have different keyboard layouts cause you’re bilingual and need access to accents or different alphabets. The normal way to switch between these two keyboards would be to show the keyboard icon on the top Menu bar and simply click on the icon and choose the keyboard layout you wish to use.

Although this works, it’s a bit annoying to mess with the mouse in search of a tiny keyboard layout icon when you just want to hop in to a keyboard layout to get an accented character, then return back to the original that you were just using.

To the rescue: Input Menu, hidden deep within System Preferences => Keyboard & Mouse => Keyboard Shortcuts => Input Menu (greyed out)

The reason Input Menu is disabled by default is that its historic keyboard shortcut has been taken over by Spotlights: Apple Key + Spacebar.

Keyboard and Mouse Preferences - Keyboard Shortcuts - Input Menu

For me, I hardly ever use Spotlight, since I’m on the Quicksilver launcher train, which pretty much circumvents my need of Spotlight, so I’m happy to give up Command + Spacebar to be able to toggle back and forth nearly instantaneously between keyboards (French AZERTY and English QWERTY). (See the great things you can do with Quicksilver here).

If you’re hot on Spotlight, simply choose a different keyboard shortcut for either Spotlight or Input Menu => Select the Previous Input Source. You can do this by double clicking on the shortcut in question and pressing the new keyboard combination to replace it with.

Fix for “caution: filename not matched” error when trying to unzip multiple files at once in Terminal.

Solution for unzipping multiple zip files with a single command.

Open up a Terminal window on OS X, go to the directory containing the zip files and enter this command:

unzip \*.zip

The forward slash escapes (prevents) the wildcard character (the “*”) from being expanded by bash shell interpreter. In English: the files in the directory are the filenames “unzip” is trying to extract from the first file it finds when using “*”.

Example:

/myzips directory contains zip files: first.zip second.zip third.zip

Trying to run: “unzip *.zip” will cause the unzip program to take “first.zip” as the archive to play with, and will look for files “second.zip” and “third.zip” within “first.zip” to expand/extract. Obviously not what you want to do.

Not escaping the * character will result in errors like: “caution: filename not matched”.

First find your current sleep setting by opening Terminal in OS X and entering this at the prompt:

pmset -g | grep hibernatemode

That should return you something like “hibernatemode 3″. Remember this number, send an email to yourself, write it down on a scratch pad, whatever it takes to remember your default mode. Mode 3 keeps your RAM powered during sleep to allow super fast wake-up, but also writes an image file of all memory onto disk in case power is lost.

To change the hibernate safe sleep setting to not create an image file on the disk, i.e. mode 0 (mode zero, not the letter ‘o’), enter the following in a Terminal window:

sudo pmset -a hibernatemode 0

Enter your password when asked to do so. This prevents Safe Sleep from saving your memory contents to disk, in large part the cause of not being able to wake MacBook’s from sleep.

If you’d like to get back about a gigabyte or more of disk space, delete the memory image file with the following Terminal command:

sudo rm /var/vm/sleepimage

Macworld has a great article with more information about safe sleep and hibernation on MacBooks.

Open the lid and nothing? Tap keys, change brightness, close and re-open lid and your MacBook still in sleep mode?

Solution: Turn off Safe Sleep. Or use Smart Sleep.

If you open your MacBook lid and notice that you can’t wake your MacBook from sleep, it’s because of the Safe Sleep system Apple designed. This system puts all your current memory (your RAM) onto the disk, so that it can power down the RAM, save energy, and keep the current working state of your computer, even if you ran out of battery power, changed batteries, etc.

Problem is, it’s slow. And buggy. Often when waking from sleep by opening the lid, the MacBook will remain in sleep.

My solution to this: don’t use Safe Sleep. Unless you’re constantly working on battery power and hate plugging in, you likely won’t ever notice you’re not using Safe Sleep’s hibernate to disk mode.

Here are some instructions on how to turn off Safe Sleep on a MacBook Pro Leopard or Tiger to avoid wake-up problems.

If you still want to use Safe Sleep with disk caching of RAM, use Smart Sleep by Patrick Stein. This software adds a preference pane to your Mac, allowing you to not use disk hibernation until you reach a low battery level, say 20% remaining battery.

Find Terminal in Leopard or Tiger

Open Finder

Go to Applications => Utilities

Double click on Terminal or highlight Terminal and Apple/Command Key + Arrow Down.

To reduce the temperature of my MacBook Pro I use smcFanControl by Hendrik Holtmann.  Normally my MacBook Pro would run somewhere close the 55-60C mark without doing anything intensive, say a 10-15% average CPU utilization.  I found this somewhat hot for my tastes, especially when using the built in keyboard where it would be uncomfortably hot to touch the speaker/heat dissipation grilles on either site of the keyboard.

I generally run the two internal MacBook Pro fans at 2600rpm each to keep the temperature 50C or below, depending on ambient temperature.  The cost is a little fan noise which is noticeable in a dead quiet room.  If you’ve got any music or background noise, you won’t notice it.  Either way, it’ll blend into the background quickly since it’s “white” noise anyways.

I’m unsure which version is the latest for smcFanControl so here’s another link to smc Fan Control version 2.1.2 in case it’s more recent than the above link.

This post was due to a comments discussion on how to turn off the macbook pro display when using an external display for Front Row.

To use an external display only when watching a movie on an external TV or projector it’s nice to not show the video on your Mac’s main display since it’s distracting. Closing the lid on a MacBook Pro makes it go to sleep and the only way to prevent the MacBook from sleeping with the lid closed is through some serious kernel hacks.

Apple’s Front Row has a feature that makes the secondary screen will go blank and dark when the Front Row is started. The trick to make your main MacBook display go blank when outputting Front Row to the secondary screen is to make your secondary screen the primary display. This is done through System Preferences => Display Preferences.

When you have the DVI to Video Adapter connected to your MacBook Pro and connected to a TV or other type of external display, open up Display Preferences. Within Display Preferences, choose Arrangement. You should see two blue squares that represent each display, main and secondary. On the main display you’ll notice a bar along the top. Simply click and drag this bar from the Main Display (usually on the left and large) to the secondary display, to make it the Primary or Main display. Close Display Preferences. Launch Front Row by hitting Apple key + Esc or by hitting the Menu on your Apple Remote. Front Row will launch and turn off the MacBook main display so that you can enjoy a distraction free viewing experience for your movies and videos on an external display.

Enjoy.

This will be painfully obvious to the old school Mac crew, but having been a recent convert from twenty years of PC’ing, I recently discovered how cool it is to play movies and videos from my Macbook Pro.  It’s like having a digital entertainment suite in your computer, complete with remote control that wows the crowd.

Front Row

Pressing Apple key + Escape key will fade out your screen to black and then Front Row will show up with selections such as Movies, which lists all video files in your Movies folder within Finder. If you’ve got your remote handy you can navigate this menu using the + and - buttons to go up and down the list, using Play/Pause to make a menu item selection. To go back or Up a menu selection you can either press the Escape key on the keyboard or the circular small Menu button on the remote.

If you haven’t already, consider install a DivX decoder and Perian so that you get great video format playback capabilities on your Mac.  Otherwise you may run into the situation where videos you’ve saved on your Mac play without sound and possibly without video either.

If you’ve noticed that your Macbook or Macbook Pro purchased in 2006 or 2007 is losing its battery life at an alarming rate, you’re not alone. Apple has had a very large batch of Sony lithium-ion polymer batteries for their laptops that are losing their maximum charge capacity very quickly.

System Profiler - Power

If you’ve noticed that your 4 hour battery life dropping to just over 2 hours recently, check your System Profiler for some information about your laptop battery power system.

System Profile can be found in Finder => Applications => Utilities => System Profiler.

Once you have System Profiler open, find Power underneath Hardware. Click on that item and on the right side of the window, scroll down until you find the Battery Information heading.

The three values we’re interested in are Full charge capacity (mAh), Cycle count, and Battery health.

A normal reading for Full charge capacity is about 5200-5400 mAh (milliamp hours). That translates into just over 4 hours battery life. Cycle count is how many times the battery has been used to capacity and recharged. Battery health is a word describing overall life expectancy and condition of the battery.

Remember that Apple has published on its Apple Support site that their laptop batteries are designed to hold 80% of its original charge capacity after 300 cycles (see the footnotes).

Doing the math, that means the Full charge capacity should be around 4160 to 4320 mAh after 300 cycles. If your Macbook battery is failing, like mine, it should read less than 3250 mAh, with a Health of “Fair” after far less than 300 cycles.

But, don’t despair. With that juicy price paid for the best laptop available on the market comes pretty good customer service. Bring your Macbook into an authorized service center, an Apple flagship store, or call up Apple support hotline and explain the situation. Also note that there are several support forum threads on Apple.com about users describing the same situation and what Apple has done for them:

http://discussions.apple.com/thread.jspa?threadID=1227431&tstart=0

http://discussions.apple.com/thread.jspa?threadID=1300374&tstart=0

For Macbook users experience battery life problems as described above the warranty coverage is being extended to two years, so even if your Macbook is out of warranty, your battery may still be in warranty.

I currently have a battery being sent to me and we’ll see how things turn out.

Good luck.

Blocked Flash AdBlocking Flash in Camino has been an On/Off affair until recently. Camino browser had implemented the FlashBlock software directly into its browser, but unfortunately, it didn’t have a whitelist where you can specify sites to allow Flash to run. So you either blocked Flash from all sites or no sites.

Although this is still the case, there is a hack that allows you to create a whitelist of sites where Flash should still be enabled. The hack is reproduced here:

Create a userContent.css file within the Camino Application Support “chrome” directory. Open up a Terminal window (found under Applications/Utilities) and enter:

cd ~/Library/Application Support/Camino/chrome
touch userContent.css

If you’ve got Textmate

mate userContent.css

If not, go into Finder, find the above “chrome” directory underneath your “Home” directory (usually your login name) and open the userContent.css file by Cmd-Clicking or two finger tap “right clicking”, Open With > Other > TextEdit.

Paste in the following code:

@-moz-document domain(youtube.com), domain(google.com)
{
object[classid*=":D27CDB6E-AE6D-11cf-96B8-444553540000"],
object[codebase*="swflash.cab"],
object[data*=".swf"],
embed[type="application/x-shockwave-flash"],
embed[src*=".swf"],
object[type="application/x-shockwave-flash"],
object[src*=".swf"]
{ -moz-binding: none !important; }
}

Notice the YouTube.com and Google.com domains within “domain()”. Add more of those with the domain of sites you want to allow Flash to run. This is your whitelist of sites where Flash is permitted to run.

After this, save the userContent.css file and shut down Camino completely (Cmd-Q) and restart it. Then go into Camino Preferences > Web Features > Block Flash animations, check this tick box.

Now try opening up YouTube.com and you should see the page working as normal. All Flash based videos should still work. Now try out a site with an obscene amount of Flash Advertisements like http://bloomberg.com. Where the Flash ads would be normally you should see the Adobe “f” instead.

If this doesn’t work for you, make sure you named the file correctly “userContent.css”, put it in the right directory “~/Library/Application Support/Camino/chrome”, and have completely shut down Camino (not just its windows, but truly Quit the program), and restarted, and that you’ve turned on the Block Flash animations option under Web Features in Preferences.

The above hack was kindly provided by Camino at http://caminobrowser.org/documentation/annoyances/

 My solution to keep Mac OS X protected from trojans and other nasty Internet virus related problems is an easy to use, easy to understand firewall software: Little Snitch.

Little Snitch FirewallHaving a virus attack your computer and render it useless is annoying. Having a trojan install itself on your computer and send out your sensitive personal information is catastrophic. What sensitive information could be that important you ask? How about Internet banking and online stock trading accounts, usernames and passwords? You don’t even need to have that information written down somewhere on your computer for it to be stolen. Keylogger programs can capture your login and passwords as you use them on your favorite sites and send them off to eagerly awaiting crackers in some far off foreign land. This actually happened to me back in 2004. Without the help of a firewall, I would never have known. More on this later.

How do we prevent our sensitive information from being beamed out to cyberspace? Setup a gate around our computer and hire a guard to watch all the traffic coming and going. Well, in a digital sense. The digital version is known as Little Snitch from Objective Development, Germany.

Little Snitch works by checking with you, a human, whenever a new program on your Mac tries to connect to the Internet. Each time a new program that tries to send information out to the Internet, Little Snitch asks you whether you want to allow this to happen and if it should remember your decision for the next time. This is really not as intrusive or bothersome as it may sound. After a day of using your computer as per normal, you’ll have just about all the programs you use normally setup with Little Snitch and the questions will stop. After this point, any time Little Snitch asks you about new outbound Internet traffic, you should pay attention: this is possibly information being sent out without your knowledge nor consent.

With Version 2 of Little Snitch, ObjDev came out with a great feature: Network Monitor. This feature unobtrusively pops up a window in the top right hand corner (by default, but moveable) with the name of the program and the Internet address it is trying to reach, every time data is sent out over the Internet. This is the ultimate in keeping a watchful eye on your system. You’ll quickly get to know which Internet addresses your Mac normally talks to on a regular basis and which addresses should set off alarm bells.

Little Snitch Network Monitor

So how is all this useful? Let me provide an example.

In 2004, I was trying to figure out some network issue with a game or what not so I popped up my firewall’s network monitor. I noticed something funny: an outgoing email connection was being attempted every minute from my computer to an email server that was completely foreign to me. I thought this somewhat odd, so I tried to load up the server address in a web browser. It was a Lycos free email account. I had no Lycos email accounts. At this point I could see the alarm bell in my head, but the ringing wasn’t too loud yet. Next I inspected what program was trying to make this Internet connection. It was a program that I had never heard of, installed in my windows directory. Looking at the compiled source code of this program it was referencing a file named “password” something or other. Returning to the directory I found this file and opened it up in a text editor. To my horror this file contained my usernames and passwords for web sites I used normally. This is when the five alarm signal started screaming in my head. In a panic I tried to delete the program, but it was constantly “in use”, making connections out to this Lycos email server, and monitoring Internet Explorer for logins that I was performing. Somehow this trojan program made it into my system, had collected all my usernames and passwords for web sites that I normally use and was trying to email them to an anonymous email account that the cracker/trojan author obviously had access to. This trojan was so successful that the email box at Lycos had hit its size limit and was rejecting incoming emails. Luckily for me, the emails with my credentials were being bounced, not delivered. The only thing that saved me was the firewall network monitor showing me the outbound connections. Had I not seen this unusual Internet traffic coming from my computer and stopped it, the cracker would have cleared out his email box, allowing new stolen passwords to arrive and I would have been compromised. I was extremely lucky.

Little Snitch 2 with Network Monitor can help you prevent this type of nightmare. If you’re interested in keeping your banking and other sensitive personal information safe, I’d certainly recommend it.

You can try Little Snitch before buying. The default install allows you to run the firewall for three hours at a time before it will switch off automatically. This will give you a flavour of how it works and what to expect. At that point you can decide whether its worth the $24.95 or not. For the piece of mind I get from knowing what information is being sent out of my computer, Little Snitch is well worth it.

What features could be improved?

  • A list of addresses or programs to not show in Network Monitor. There are a bunch of Internet addresses that my programs talk to on a regular basis. I don’t need to see these constantly in the Monitor. Example: GMail connects to its servers every few seconds to check for new mail. Obviously an allowed action, but, very repetitive and not interesting from a security standpoint. Being able to setup a “whitelist” of addresses with programs for Network Monitor to ignore would be nice. UPDATE 080207: After writing this review, Karl from Objective Development was kind enough to let me know that this feature is already available and I had simply missed it.  To not show a program within Network Monitor simply select the program  within Network Monitor you wish to exclude then click on the “gear” symbol within the pop-up monitor window.  One of the choices from the pop-up menu is “Don’t show [program] within Network Monitor”.
  • Opacity of the Network Monitor window. I’d like to adjust the transparency so it doesn’t affect the visibility of the programs I’m using below the Network Monitor when it pops up.
  • The purchase clearing house Objective Development has chosen for North America: Plimus. These guys are slow, unresponsive, and annoying. Why?
  1. It takes them 12+ hours to complete an order.
  2. No one answers their phones PLUS its very difficult to find the number for customer service reps (they ask you to repeat the order and choose “Pay by Phone” in order to get the customer service number. I’m not kidding). I phoned in multiple times at the 12 hour mark trying to get the order completed, to be greeted only with recorded messages asking me to leave a message (as no one was answering) and someone would call me back. I finally stumbled upon the correct phone menu choices which allowed me to confirm and complete my order without having to talk to anyone. In my opinion, what’s the point of having an automated system that forces order confirmation by a service representative, when the original person ordering can enter the system and confirm the order themselves? Doesn’t that defeat the purpose of having a third party verify and check for fraud?!?
  3. They lie about having tried to contact you to confirm the order. After about 8 hours I received an email from them saying “your order couldn’t be confirmed because your phone number was incorrect or you could not be reached”. Since I have a Skype number which records all incoming call attempts, I know when someone has dialed my number. No one had dialed my number. To make sure I didn’t enter my phone number incorrectly on the order form I found my order on their website. Sure enough, I had listed the correct phone number. Thus, they were lying when they sent the email saying they had tried to contact me. Why would they do this? It allows them to be slow in confirming orders and it maintains their “claimed” service response times by asking the purchaser to “correct” their phone number. In most cases it takes a few hours for users to read and respond to such emails, giving Plimus extra time to get around to processing the order. This is weak. And it pisses people off, laying the blame on the customer in order to justify their slow turnaround time. Whether this practice is employed by the line employees without management knowledge, or whether it is an accepted practice at Plimus, it’s poor customer service. I would encourage Objective Development to find a better service provider for North America. If I had had the choice to cancel and refund my order, I likely would have, all due to Plimus’ poor service. This is unfortunate, considering that Little Snitch is a great a program.

Enough complaining. Little Snitch rocks. Danke ObjDev!

Update: This post has been superseded by How to Fix Ajax Error: permission denied to call method XMLHttpRequest.open.

For anyone developing S-controls and applications for use in Salesforce.com, developing directly within their platform is a bit of a hurdle. Using their Ajax Tools Development Environment for quick changes is fine. But, developing a serious piece of code purely using that tool is far from a pleasant reality today. Hence its natural to develop on a local machine then upload to Salesforce.com when a piece of software is ready for testing within the platform.

When trying to use the Ajax Toolkit connection.js library locally, you’ll encounter a cross domain scripting error:

“Permission denied to call method XMLHttpRequest.open”

Cross domain scripting is not allowed by default in Mozilla based browsers (Firefox, Camino, etc.).

To override this security feature you need to add the following line to your XMLHttpRequest code before issuing an open() call:

netscape.security.PrivilegeManager.enablePrivilege(“UniversalBrowserRead”);

This allows the user agent (browser) to ignore cross-domain scripting warnings, which are a major source of cracking attacks.

There are one or two more steps required to make this work depending on whether you’re using Firefox or Camino. The following step is the same for any Mozilla borwser, be it Firefox, Camino, or any other Mozilla based web browser agent.

In the browser address window type:

about:config

This opens the Mozilla configuration file which you can filter using the field at the top of the screen and edit items by double clicking on them.

Find signed.applets.codebase_principal_support
Top Secret!
By default it should be set to false. Double clicking it should set it to true.

For Firefox users, this next step is also necessary: adding a capability.policy line to the user.js config file which contains all user preference settings for the browser. Regardless of which operating system you’re using, user.js does not exist by default. Therefore, you must create this file, then add the appropriate settings into it. The settings from user.js get copied to prefs.js, which is the actual file read by Firefox.

On Mac OS X the correct directory to create this file within is:

~/Library/Application\ Support/Firefox/Profiles/[alphanums].default/

On Win XP or 200:
C:\Documents and Settings\[User Name]\Application Data\Mozilla\Firefox\Profiles\

See this Mozilla page on Editing config settings for more details and examples on locations for this file.

Note that [alphanums].default is a jumble of letters and numbers “dot” default and it is a directory. For example “o3dfi34z.default”. Within this directory create a file named “user.js”. Within this file add the following three lines:


user_pref("capability.policy.XMLHttpRequestToAnySite.XMLHttpRequest.open", "allAccess");
user_pref("capability.policy.XMLHttpRequestToAnySite.sites", "http://localhost.com:3000");
user_pref("capability.policy.policynames", "XMLHttpRequestToAnySite");

Now note that “http://localhost.com:3000″ is only in my case. Whatever your local development location is, use that, be it “http://localhost”, “http://192.168.1.1″, etc. etc., use that. Be exact with this site address. It matters. For me, that port number was required for Firefox to allow me to send XMLHttpRequests to another domain without being denied.

Try running the XMLHttpRequest again and hopefully your Permission denied to call method XMLHttpRequest.open error has disappeared.

For those of you trying to use the Salesforce.com connection.js Ajax library locally, these are the following edits I made to make this happen. The following line numbers relate to version 11.1 of connection.js.

Find the definition of sforce.Transport, which should be around line 565.
Find the line: this.connection.open("POST", this.url, async); around line 591.
Add the following line before the previous line:

netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");

Change the relative URL paths for the Salesforce API from “/services/Soap/u/11.0″ to the following:

"https://www.salesforce.com/services/Soap/u/11.1"

A nice way to do this is simply add a constant at the top of connection.js and just replace all occurrences of the relative path with this constant:

const sforce_api_url = "https://www.salesforce.com/services/Soap/u/11.1"

After that, fire up your trusty browser and try making your Ajax Toolkit call again.

You may find it helpful to use a Javascript development environment like Jesse Ruderman’s Javascript Development Environment 2.0.1 when playing around with Javascript. [Jesse, you're the man]. Install it as a bookmarklet for the best user experience. It allows you to access all the javascript code and the document model in your current browser window through this development environment (which opens up in a new window).

Don’t forget the about:config stuff with the browser up above.

And finally, this is for debugging purposes on your local machine. Don’t publish code which disables security settings (which are there for a good reason) to a live deployment environment, such as Salesforce.com. Normally you’ll be installing the code you’re building as an S-control anyways, within the Salesforce.com platform, which will be exempt from any cross-site cross-domain scripting issues.


Have an .mkv movie file? Wondering what the heck it is and how to play it?

High Definition movies in 720 or 1080 pixel width format are often encoded and packaged as a Matroska format video with a .mkv file extension.

Apple QuickTime doesn’t handle this format natively so you have to add a package handler for mkv files to QuickTime to play .mkv files.

A quick and easy solution to how to play .mkv files is to install Perian, which makes QuickTime play .avi, .flv, and .mkv files and handles many different and popular encoding formats for video.

Perian for QuickTime

Remember to fully quit and re-launch QuickTime after installing Perian (don’t just close the QuickTime window, it’s still running until you Quit the program). This allows QuickTime to reload its list of handled formats and encodings.

When double clicking on an .mkv file to play it, you may have to wait until the entire film is buffered in QuickTime before it will play smoothly. You can tell the progress of the buffering by looking at the grey timeline bar that is inching across the bottom left of the QuickTime window, starting near the 00:00 time marker. This is one of the oddities of the .mkv Matroska video package format. Don’t ask me why this happens, just keep this in mind next time you want to watch an mkv video on your Mac use Perian.

Debugging Flash / Adobe Flex 2 / ActionScript 3 code using fdb on Mac or Windows is not exactly a straightforward affair. The following are instructions on how to get fdb running for debugging flash files and how to debug flex through the command line tools.

Preamble:

  • Verify that you have a debug capable version of Flash Player 9 (or more recent) on your Mac or Windows machine. You normally get this by default if you’ve installed the Adobe Flex SDK 2 or Adobe Flex Builder 2 / 3 (and have not installed/updated Flash Player since then). All web browsers that you had installed at the time of your Flex Builder / SDK installation should be updated with the Debugger versions of Flash Player 9. To check that your version of Flash Player is debug enabled, just open up any web page that has a flash component within it such as Google Finance and right click on the flash component within the browser window. You should see a context menu pop up with a “Debugger” menu item, which may or may not be greyed out. Adobe Flash Player Debugger
  • Verify that you have Adobe Flex SDK 2 installed or Adobe Flex Builder 2 / 3 installed (which contains the SDK as part of the Flex Builder install). If you’re on a Mac, the Adobe Flex SDK 2 is installed into /Applications/Adobe Flex Builder 2/Flex SDK 2, so open up Finder and check that you’ve got this Folder/directory available in /Applications.
  • create a symbolic link to the fdb program:

sudo ln -s /Applications/Adobe\ Flex\ Builder\ 2/Flex\ SDK\ 2/lib/fdb.jar /usr/local/lib/fdb.jar
sudo ln -s /Applications/Adobe\ Flex\ Builder\ 2/Flex\ SDK\ 2/bin/fdb /usr/local/bin/fdb

The following example debugs a flash file named salesforce-debug.swf. Note that you don’t debug your regular production compiled flash file, you debug, the “debug” version, which is automatically created for you when you compile your flash file or project. These files are normally located within the /bin directory of your Flex project.
If the following example, when you see prompts such as ‘$’ or ‘(fdb)’, do not mistake them for commands, those are my prompts and you should be typing what follows those prompts. Lines not preceded by either a bullet or prompts are output from the fdb program.

To debug a Flash .swf using fdb on a Mac:

  • launch the Terminal program (from /Applications/Utilities/Terminal)
  • change directories / folders until you’re in the same directory as the .swf file you want to debug
  • launch fdb

$ fdb

  • when you start up fdb you should see an fdb prompt: (fdb)
  • you need to specify the .swf file you want fdb to hook into and debug

(fdb) file salesforce-debug.swf
(fdb) run
Attempting to launch and connect to Player using URL
salesforce-debug.swf
Player connected; session starting.
Set breakpoints and then type ‘continue’ to resume the session.
[SWF] Users:ben:Documents:Flex Builder 2:salesforce:bin:salesforce-debug.swf - 1,101,498 bytes after decompression

  • At this point a browser window should pop-up and begin to load your flash .swf file, but it will not finish loading until you’ve set your breakpoints and tell fdb to ‘continue‘. Setup your breakpoints now by using the ‘break’ keyword followed by a function name or a line number. In the following I set a breakpoint in my function ’sfquery’ which will stop the Flash .swf when it hits this function and you’ll get a prompt in fdb debugger.

(fdb) break sfquery
Breakpoint 1 created, but not yet resolved.
The breakpoint will be resolved when the corresponding file or function is loaded.

  • At this point the browser window with the half-loaded Flash file is still hung at “Loading…”. Repeat with as many breakpoints as you need. When done with breakpoints, you must issue a ‘continue’ command to get Flash to continue loading the .swf for debugging.

(fdb) continue
Additional ActionScript code has been loaded from a SWF or a frame.
To see all currently loaded files, type ‘info files’.
Resolved breakpoint 1 to salesforce.mxml:64

  • Ok, this step is key to the debugging setup in Flex… you have to hit Return/Enter at an empty fdb prompt in order to get the your Flash file / Flex project to actually finish loading and to run in the browser window when in debug mode. No, there are no instructions for this, you just have to figure this out on your own through trial and error. Before this the browser window should have the Flash file running but frozen and “loading” until you hit the Enter key while in the fdb debugger, which is the next step:

(fdb)