File associations in Linux (Gnome and Mailcap)

File associations in Linux can be tricky. On my Gnome-based Ubuntu machine, I can associate a filetype by right-clicking a file in Nautilus, and slecting “Open with”. To modify the defaults using config files, this post describes it well. Basically, the two main locations to check out are /usr/share/applications/defaults.list and ~/.local/share/applications/. File associations made using these methods apply to the commands gnome-open and xdg-open as well.

File associations in the command line is mainly done via MIME types (I think). At least file associations in conkeror, org-mode’s org-open-at-point (also look at org-file-app), and the see commands are done by MIME. MIME handlers are defined in a user’s ~/.mailcap file.

I think this information is enough to modify default apps throughout Linux. Do see this post where I outline how I launch all my files using Emacs’ dired mode. Now I can launch apps more uniformly in Nautlius, Emacs, and on the command line based on configuring default apps.

Burn CD’s and DVD’s from emacs using dired and dvd+rw-tools

I recently explored burning discs from the command line. To make things even more convenient, I can employ emacs dired to help in selecting the files. That is, suppose I have some files in a directory opened in dired. I can mark the files I want to be burnt, and invoke ! (dired-do-shell-command) on those files with the command:

 <pre class="src src-sh">growisofs -dvd-compat -input-charset=ISO-8859-1 -full-iso9660-filenames -Z /dev/sr0 -R -J -pad * &amp;&amp; eject /dev/sr0

I can also invoke & (dired-do-async-shell-command) with the above command without the && eject /dev/sr0 (the * arguments will also be passed to this) to continue using the current emacs instance and view the progress in stdout.

file management: emacs dired to replace Finder in mac os x (and other OS)

I hate Finder in Mac OS X. I mean, it looks nice and all, but it is not customizable. I really liked the KDE window management back when I used Kubuntu because I can select/de-select files with the keyboard, cut/paste/copy files with the keyboard, have shortcuts to different locations, etc. Finder has some keyboard shortcuts, but not at all flexible. You can copy and paste files, but you can’t cut and paste files. Selecting/de-selecting files is not as flexible (eg, skipping a file). I can’t go to the sidebar window where all my bookmarked locations reside using the keyboard. Finder, and in general Mac OS X, is not so flexible. This bugs me a lot. I wanted to get stumpwm working in OS X so that things are more keyboard-oriented. However, it doesnt work with all the native mac apps. The fix is with dired mode in emacs. I spend most of my time in emacs already. With dired, I can even manage files inside emacs (I can do so in the shell, but this makes browsing and executing commands on files a breeze). Use “C-x f” and navigate to a location rather than a file. Learn all the keyboard shortcuts for delete, rename, execute shell command, etc. You can even cut/copy/paste with wuxch-dired-copy-paste. The functions below also allow me to open files the Mac way, with the “open” command. This is cool because files will be opened with the native Mac default application.

<pre class="src src-sh">;;

;; copy and paste files in dired ;; needed additional files, such as dired+, dired-details+, find-dired+, and find-dired- (require ‘wuxch-dired) (require ‘wuxch-dired-copy-paste) ;; ;; (defun dired-do-shell-mac-open-vqn () ;; (interactive) ;; (dired-do-async-shell-command ;; “open” current-prefix-arg ;; (dired-get-marked-files t current-prefix-arg))) (defun dired-do-shell-mac-open-vqn () (interactive) (save-window-excursion (dired-do-async-shell-command “open” current-prefix-arg (dired-get-marked-files t current-prefix-arg))))

(define-key dired-mode-map (kbd “s-o”) ‘dired-do-shell-mac-open-vqn)

I can use Apple-o/Windows-o to open files with the default mac program for the marked files.I also use emacs’ bookmark system (“C-x r b” and “C-x r m”) to bookmark locations.Note that all this is not specific to Mac OS X. Dired’s been around forever – I just never picked it up really. Now with my “open” trick and the bookmark system, this should really replace my use of Finder in Mac OS X.

Update 11/10/2010 – On Linux

I’m back on Linux now. A few updates on launching files with the default application. Add the following to the emacs init file:

(defun dired-do-shell-launch-file-default ()
 "$HOME/Documents/bin/" current-prefix-arg ;; linux;; multiple files
 ;; "nohup xdg-open" current-prefix-arg ;; linux can open multiple files, but one at a time
 ;; "see" current-prefix-arg ;; linux;; can open at most 1 file (being opened)
 ;; "open" current-prefix-arg ;; mac os x
 (dired-get-marked-files t current-prefix-arg))))
(define-key dired-mode-map (kbd "s-o") 'dired-do-shell-launch-file-default)

Need the script (thank you fledermaus from #emacs):

#! /bin/bash

for file in "$@"
nohup xdg-open "$file" &
sleep 1

Now, to unmount devices in emacs:

;; unmount disk in dired
(defun dired-do-shell-unmount-device ()
 "umount" current-prefix-arg ;; linux
 ;; "diskutil unmount" current-prefix-arg ;; mac os x
 (dired-get-marked-files t current-prefix-arg))))
(define-key dired-mode-map (kbd "s-u") 'dired-do-shell-unmount-device)

If an error is returned, make sure the device is not being used anywhere, including opened in nautilus or in some terminal.

The ability to launch files with the default application (look into xdg-open, gnome-open, and see), unmnount devices, and being able to copy/paste files in emacs help makes dired the perfect file manager. I will use this from now on over Nautilus. It’ll compliment using stumpwm.