From 1b0abee054235ea4ac7589dd92d3939e1386d24a Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 12 Oct 2010 23:39:29 +0200 Subject: Initial contents --- sys/furl.applescript | 1 + sys/jao-applescript.el | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ sys/jao-devon.el | 42 ++++++++++++++++++++++++++++++++ sys/jao-osd.el | 55 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 sys/furl.applescript create mode 100644 sys/jao-applescript.el create mode 100644 sys/jao-devon.el create mode 100644 sys/jao-osd.el (limited to 'sys') diff --git a/sys/furl.applescript b/sys/furl.applescript new file mode 100644 index 0000000..6823ff0 --- /dev/null +++ b/sys/furl.applescript @@ -0,0 +1 @@ +tell application "Firefox" to get Çclass curlÈ of window 1 diff --git a/sys/jao-applescript.el b/sys/jao-applescript.el new file mode 100644 index 0000000..233186c --- /dev/null +++ b/sys/jao-applescript.el @@ -0,0 +1,65 @@ +;;; AppleScript and some macish bits +(autoload 'applescript-mode "applescript-mode" + "major mode for editing AppleScript source." t) +(setq auto-mode-alist + (cons '("\\.applescript$" . applescript-mode) auto-mode-alist)) + +(defun do-applescript (script) + (with-temp-buffer + (insert script) + (shell-command-on-region (point-min) (point-max) "osascript" t) + (buffer-string))) + +(defun jao-as-tell-app (app something) + (let ((res (do-applescript (format "tell application \"%s\"\n%s\nend tell" + app something)))) + (or (and (stringp res) (substring res 0 -1)) ""))) + +(defmacro jao-as-get-doc (name application &optional doc) + `(defun ,name () + (interactive) + (let ((url (jao-as-tell-app ,application + ,(format "get the URL of %s 1" + (or doc "document")))) + (name (jao-as-tell-app ,application "get the name of document 1"))) + (cons url name)))) +(jao-as-get-doc jao-as-safari-doc "Safari") +(jao-as-get-doc jao-as-webkit-doc "WebKit") +(jao-as-get-doc jao-as-camino-doc "Camino" "window") + +(defun jao-as-firefox-doc () + (interactive) + (let ((url (shell-command-to-string + (concat "osascript " + (expand-file-name "furl.applescript" + (file-name-directory load-file-name))))) + (name (jao-as-tell-app "Firefox" "get the name of window 1"))) + (cons (substring url 0 -1) name))) + + +;;; quicksilver +(defun jao-qs-buffer () + "Opens the current file in Quicksilver" + (interactive) + (cond ((and buffer-file-name (file-exists-p buffer-file-name)) + (call-process-shell-command (concat "qs \"" buffer-file-name "\""))) + ;; dired handling + ((eq major-mode 'dired-mode) + (dired-do-shell-command "qs * " + current-prefix-arg + (dired-get-marked-files t current-prefix-arg))) + ;; buffer-menu mode + ((and (eq major-mode 'Buffer-menu-mode) + (file-exists-p (buffer-file-name (Buffer-menu-buffer nil)))) + (call-process-shell-command + (concat "qs \"" (buffer-file-name (Buffer-menu-buffer nil)) "\""))) + (t + (error "Not visiting a file or file doesn't exist")))) + + (defun jao-qs-region (start end) + "Opens the contents of the region in Quicksilver as text." + (interactive "r") + (call-process-region start end "qs" nil 0 nil "-")) + + +(provide 'jao-applescript) diff --git a/sys/jao-devon.el b/sys/jao-devon.el new file mode 100644 index 0000000..417cb6d --- /dev/null +++ b/sys/jao-devon.el @@ -0,0 +1,42 @@ +;; DEVONthink interaction + +(require 'jao-applescript) + +(defconst *jao-devon-sep* "####") + +(defun jao-devon-path (dvp) + (car (split-string dvp *jao-devon-sep*))) +(defun jao-devon-url (dvp) + (cadr (split-string dvp *jao-devon-sep*))) +(defun jao-devon-name (dvp) + (car (last (split-string (jao-devon-path dvp) "/")))) + +(defun jao-devon-make-dvp (path url) (concat path *jao-devon-sep* name)) +(defun jao-devon-dvp-p (dvp) + (and (stringp dvp) + (string-match (concat "^/.+" *jao-devon-sep*) dvp))) + +(defconst *jao-devon-sel-as* + (concat "set rs to the selection + set r to item 1 of rs + set rn to the name of r + set rl to the location of r + set ru to the URL of r + rl & rn & \"" *jao-devon-sep* "\" & ru")) + +(defun jao-devon-selection () + (interactive) + (jao-as-tell-app "DEVONThink Pro" *jao-devon-sel-as*)) + +(defun jao-devon-open-as (path) + (concat "set r to get record at \"" path "\"" + "\n open window for record r\n activate")) + +(defun jao-devon-open (dvp) + (if (eq system-type 'darwin) + (let ((path (jao-devon-path dvp))) + (when path + (jao-as-tell-app "DEVONThink Pro" (jao-devon-open-as path) t))) + (browse-url (jao-devon-url dvp)))) + +(provide 'jao-devon) diff --git a/sys/jao-osd.el b/sys/jao-osd.el new file mode 100644 index 0000000..0b2c433 --- /dev/null +++ b/sys/jao-osd.el @@ -0,0 +1,55 @@ +;; candy +(defvar jao-osd-cat-color-fg "black") +(defvar jao-osd-cat-color-bg "white") +(defvar jao-osd-cat-font "Andika Basic 16") +(defun jao-osd-cat-font (&optional font) + (or font jao-osd-cat-font)) + +(defun jao-osd-process-args (&optional font fg bg) + `("-n" ,(jao-osd-cat-font font) + "-R" ,(or bg jao-osd-cat-color-fg) "-B" ,(or fg jao-osd-cat-color-bg) + "-b" "200" "-r" "255" + "-e" "0" "-t" "2" "-d" "10" "-p" "0" "-x" "10" "-y" "10" "-u" "5000")) + +(setq jao-osd-processes (make-hash-table)) + +(defsubst jao-osd--delete-process (name) + (remhash name jao-osd-processes)) + +(defun jao-osd-process (name &optional font color) + (let ((proc (gethash name jao-osd-processes))) + (or (and proc (eq (process-status proc) 'run) proc) + (puthash name + (apply 'start-process + `("notifications" + ,(format "*notifications/%s*" name) + "aosd_cat" + ,@(jao-osd-process-args))) + jao-osd-processes)))) + +(defun jao-osd-cat (name lines) + (let* ((proc (jao-osd-process name)) + (lines (if (listp lines) lines (list lines))) + (trail (- 5 (length lines)))) + (when proc + (dolist (line lines) + (send-string proc (format "%s\n" line)))))) + ; (when (> trail 0) (send-string proc (make-string trail ?\n)))))) + +(defun jao-osd--names () + (let (names) + (maphash (lambda (n k) (push n names)) jao-osd-processes) + (reverse names))) + +(defun jao-osd-kill (name) + (let ((proc (gethash name jao-osd-processes))) + (when (processp proc) + (kill-process proc)))) + +(defun jao-osd-kill-notifiers () + (interactive) + (maphash (lambda (n p) (ignore-errors (kill-process p))) jao-osd-processes) + (clrhash jao-osd-processes)) + +(provide 'jao-osd) + -- cgit v1.2.3