Be Among the 20% of the Best!

Safari and IE

| comments

Some websites just have to accept only Internet Explorer (I know, disgusting). The admins/developers (or their clients?) don’t seem to know there are other operating systems available, except for windows. Working on Mac is a no-no for them. The following is a little note of how I fought one of such sites.

/* Update on Feb 16, 2013: add simple aliases for quick change. Since the time of writing this post, I’ve come across the tool called defaults that comes with OS X, and allows to read/write configs easier. Therefore, I’ve added the following simple aliases to my ~/.zshrc/~/.bashrc:

alias safari_be_ie='defaults write CustomUserAgent "\"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)\""'
alias safari_be_safari='defaults write CustomUserAgent ""'

The names of the aliases define the function. The nice thing here is that after issuing one of these commands, new Safari windows will have the set user agent. */

Here are some steps I took to trick a site into believing I used IE while using Safari actually. First of all, enable Safari’s debug menu to be able to change your User-Agent:

defaults write IncludeDebugMenu 1

Restart the app, open the site, select Develop / User Agent / Internet Explorer 9.0, and make sure the current page works as needed. It’d be the end of the story, but Safari doesn’t save the option even for new tabs, let alone after restarts. Have to change the default user agent then with the help of an old article about that.

I opened the ~/Library/Preferences/ file, in vim of course, and… it turned out to be of binary plist format. I knew there was a tool to convert between plist formats, but we have vim here, don’t we? There must be a way to do the conversion automatically! Thanks to the article, I placed the script in ~/.vim directory and appended my .vimrc file with the following:

source ~/.vim/vim_plist_script.txt

Now vim can edit binary plist files. So, open the ~/Library/Preferences/ file and add the lines:

<string>Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)</string>

Restart Safari, and IE 9.0 should be your default user agent. I comprehend it’s not a very useful thing to do in general, but I don’t use Safari for other sites anyway.

A better option would be to have a different setup for Safari, so I could run two Safaris with different user agents. However, I couldn’t find any information about this feature.