*NIX Tricks

[osx] Do not let Safari open PDF files by itself — use an external viewer

Posted in cli, osx by kousik on February 13, 2010

Safari (4.0.4) shows PDFs in the browser window by default when you click on a hyperlink to a PDF file. What is happening here is that when you click on the link, Safari downloads the file in the /tmp directory and opens it by itself. I don’t want that — I want to open it in a stand-alone PDF viewer, say Skim, which will allow me to do other PDF-related stuff (e.g. annotation). A command line trick will do the job (enter the following command after the prompt, indicated by $ here, in the terminal):

$ defaults write com.apple.Safari WebKitOmitPDFSupport -bool YES

If you want to go back to the default behavior use the same command but change ‘YES’ to ‘NO’.

NOTE: You may run across a totally different issue which will force you to view a PDF file in the browser window if you have Adobe reader plugin installed. In that case just remove that plugin from the following directories:
/Library/"Internet Plug-Ins"
~/Library/"Internet Plug-Ins"

I have tested this on Mac OSX  - Leopard (10.5.8).

Credit: Mac Rumors forum.

[osx] Force Safari to open links in a new tab instead of a new window

Posted in osx by kousik on February 9, 2010

In my Macbook (Lepard: OSX  version 10.5.8), Safari (version 4.0.4) in general opens a new link in a new window instead of a new tab if the link has target="_blank" attribute. It just gets in my way of organizing things.

To force the link open in a new tab use the following command (without my favorite prompt sign “$”) in the terminal and restart Safari:

$ defaults write com.apple.Safari TargetedClicksCreateTabs -bool true

Notes: 1. This will open the link in the foreground. Command+click will however open the link the background (even without the above trick).

2. Change `true’ to `false’ to revert back to the default behavior.

Credit: MacOSX hints.

Tagged with: , , , , ,

[osx] Restart a frozen Dock from the command line

Posted in osx by kousik on November 6, 2009

I am having some problem with the X11 lately on my Mac OSX (Leopard). I have not found a solution yet — when I do I’ll sure put it up here. But a stuck X11 window in the dock caused it to freeze up. Along with that all the fancy cover switch and other related stuff are also gone! Luckily the spotlight accepted the Command+spacebar combination and let me find terminal.app from there.

However, although I knew who the culprit was (using htop) but I cannot kill it (kill -9 kills it, but it revives!). But the following command did the trick:

$ killall Dock

It’ll kill the Dock application and then restart it instantly. (Although it did not kill the culprit, x11).

I’m yet to find a solution for the x11 problem!

Tagged with: , , , ,

[osx] Eject a volume ‘unwilling’ to be ejected!

Posted in linux, osx, unix by kousik on October 31, 2009

I sometime have problem finding which persistent process is not letting me eject a volume (CD/DVD/USB drive). The error message is not very helpful at all:

Try quitting applications

OK, but which one(s)? I often have hard time figuring that out using htop/ top or a combination of ps and grep.

But actually this is what I want:

$ lsof | grep -i Volume_Name

where Volume_Name is the name of the volume (or an ‘identifying’ part of the name) I want to eject. This gives me the name(s) and process ID(s) of the run-away process(es) as well as the path to the file(s) in use on the volume, Volume_Name.

Now that I know the names I should first try to save the documents and quit the applications involved in the normal way. However, if a particular application does not oblige, I can always kill it (with the risk of potential data loss!) using its process ID (say, 123):

$ kill -9 123

After that, the ejection of the volume should not be difficult at all.

Needless to say, being a Unix utility, lsof (=“list open files”) may be used on other *nix-based systems as well.

[osx] Change the hostname in Mac (leopard)

Posted in osx by kousik on August 29, 2009

For a last few days my Macbook “assumed” a weird hostname: kousik-mac(2) — I don’t know what I did that caused it. Here are three ways to change it (I don’t know if these qualify to be “NIX tricks” :D ):

1. Click at the Sharing option in System Preferences and then click at Edit. You may change the computer name as well.

2. Use the following commandline-fu:
$ sudo scutil --set HostName your-preferred-hostname

3. Edit the preference file
$ sudo vi /Library/Preferences/SystemConfiguration/preferences.plist
Search for LocalHostname and change the text within the  <string>...</string> just under it. While you’re at it, you may want to change the string under ComputerName (need I say what it does?), as well — this key comes just after the previous one (HostName).

Tagged with: , , , ,
Follow

Get every new post delivered to your Inbox.