Skip to content

Instantly share code, notes, and snippets.

@sabof
Last active August 29, 2015 14:01
Show Gist options
  • Save sabof/5528535a4726b1b908f0 to your computer and use it in GitHub Desktop.
Save sabof/5528535a4726b1b908f0 to your computer and use it in GitHub Desktop.
emacs-automount
;; -*- lexical-binding: t -*-
(require 'cl-lib)
(require 'dbus)
(cl-flet (( udisks-register-signal (&rest args)
(apply 'dbus-register-signal
:system "org.freedesktop.UDisks"
"/org/freedesktop/UDisks"
"org.freedesktop.UDisks"
args))
( udisks-call-method (&rest args)
(apply 'dbus-call-method
:system "org.freedesktop.UDisks"
(car args)
"org.freedesktop.UDisks.Device"
(cdr args)))
( udisks-get-property (&rest args)
(apply 'dbus-get-property
:system "org.freedesktop.UDisks"
(car args)
"org.freedesktop.UDisks.Device"
(cdr args))))
(udisks-register-signal
"DeviceAdded"
(lambda (disk-path)
(let (mount-point)
(and (udisks-get-property disk-path "DeviceIsPartition")
(equal (udisks-get-property disk-path "IdUsage")
"filesystem")
(not (udisks-get-property disk-path "DeviceIsOpticalDisc"))
(setq mount-point
(udisks-call-method disk-path
"FilesystemMount"
(udisks-get-property disk-path "IdType")
'(:array)))
(message "Mounted to: %s" mount-point)))
)))
(provide 'emacs-automount)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment