Permalink
Browse files

Moved all functionality into one file, and added a menu keymap bound …

…to C-c g in org-mode
  • Loading branch information...
1 parent aacff20 commit 519abbb6aa0bcade2d296848c5ddf67c43cb2937 alander committed Mar 30, 2010
Showing with 11 additions and 179 deletions.
  1. +0 −83 lisp/org-mac-firefox.el
  2. +11 −11 lisp/org-mac-link-grabber.el
  3. +0 −85 lisp/org-mac-together.el
View
@@ -1,83 +0,0 @@
-;;; org-mac-firefox.el --- Grab Firefox.app urls and insert them as links into org-mode documents
-;;
-;; Copyright (c) 2010 Anthony Lander
-;;
-;; Author: Anthony Lander <anthony.lander@gmail.com>
-;;
-;;; Commentary:
-;;
-;; This code allows you to grab the current active url from the main
-;; Firefox.app window, and insert it as a link into an org-mode
-;; document. Unfortunately, firefox does not expose an applescript
-;; dictionary, so this is necessarily introduces some limitations.
-;;
-;; The applescript to grab the url from Firefox.app uses the System
-;; Events application to give focus to the firefox application, select
-;; the contents of the url bar, and copy it. It then uses the title of
-;; the window as the text of the link. There is no way to grab links
-;; from other open tabs, and further, if there is more than one window
-;; open, it is not clear which one will be used (though emperically it
-;; seems that it is always the last active window).
-;;
-;; This code is heavily based on org-mac-message.el written by John
-;; Weigley and Christopher Suckling.
-;;
-;;
-;; Installation:
-;;
-;; add ('require org-mac-firefox) to your .emacs, and then,
-;; optionally, define a key binding like this:
-;;
-;; (add-hook 'org-mode-hook (lambda ()
-;; (define-key org-mode-map (kbd "C-c f") 'org-mac-firefox-insert-frontmost-url)))
-;;
-;; Usage:
-;;
-;; Either use the keybinding you defined above or type M-x
-;; org-mac-firefox-insert-frontmost-url RET to grab the frontmost
-;; Firefox.app link and insert it into your org-mode document at
-;; point.
-;;
-;;; Code:
-
-(defun as-mac-firefox-get-frontmost-url ()
- (let ((result (do-applescript
- (concat
- "set oldClipboard to the clipboard\n"
- "set frontmostApplication to path to frontmost application\n"
- "tell application \"Firefox\"\n"
- " activate\n"
- " delay 0.15\n"
- " tell application \"System Events\"\n"
- " keystroke \"l\" using command down\n"
- " keystroke \"c\" using command down\n"
- " end tell\n"
- " delay 0.15\n"
- " set theUrl to the clipboard\n"
- " set the clipboard to oldClipboard\n"
- " set theResult to (get theUrl) & \"::split::\" & (get name of window 1)\n"
- "end tell\n"
- "activate application (frontmostApplication as text)\n"
- "return theResult\n"))))
- (car (split-string result "[\r\n]+" t))))
-
-(defun org-mac-firefox-get-frontmost-url ()
- (interactive)
- (message "Applescript: Getting Firefox url...")
- (let* ((url-and-title (as-mac-firefox-get-frontmost-url))
- (split-link (split-string url-and-title "::split::"))
- (URL (car split-link))
- (description (cadr split-link))
- (org-link))
- (when (not (string= URL ""))
- (setq org-link (org-make-link-string URL description)))
- (kill-new org-link)
- org-link))
-
-(defun org-mac-firefox-insert-frontmost-url ()
- (interactive)
- (insert (org-mac-firefox-get-frontmost-url)))
-
-(provide 'org-mac-firefox)
-
-;;; org-mac-firefox.el ends here
@@ -1,3 +1,4 @@
+
;;; org-mac-link-grabber.el --- Grab links and url from various mac
;;; application and insert them as links into org-mode documents
;;
@@ -14,9 +15,9 @@
;; This code is heavily based on org-mac-message.el written by John
;; Weigley and Christopher Suckling.
;;
-;; Detailed comments for each application are inlined with the code.
-;; Here is a brief overview of how the code interacts with each
-;; application:
+;; Detailed comments for each application interface are inlined with
+;; the code. Here is a brief overview of how the code interacts with
+;; each application:
;;
;; Firefox.app - Grab the url of the frontmost tab in the topmost window
;; Together.app - Grab links to the selected items in the library list
@@ -40,13 +41,14 @@
;; Define key bindings. C-g is the prefix key to grab links.
-(define-key org-mode-map (kbd "C-c g")
- (define-prefix-command 'org-mac-grab-link-keymap nil "Grab links from [m]ail.app [f]irefox [t]ogether"))
+(progn
+ (define-key org-mode-map (kbd "C-c g")
+ (define-prefix-command 'org-mac-grab-link-keymap nil "Grab links from [m]ail.app [f]irefox [t]ogether"))
-(define-key org-mac-grab-link-keymap "m" 'org-mac-together-item-get-selected)
-(define-key org-mac-grab-link-keymap "f" 'org-mac-firefox-insert-frontmost-url)
-(define-key org-mac-grab-link-keymap "t" 'org-mac-together-item-get-selected)
-(define-key org-mac-grab-link-keymap (kbd "C-g") 'keyboard-quit)
+ (define-key org-mac-grab-link-keymap "m" 'org-mac-message-insert-selected)
+ (define-key org-mac-grab-link-keymap "f" 'org-mac-firefox-insert-frontmost-url)
+ (define-key org-mac-grab-link-keymap "t" 'org-mac-together-item-get-selected)
+ (define-key org-mac-grab-link-keymap (kbd "C-g") 'keyboard-quit))
@@ -154,8 +156,6 @@
(interactive)
(insert (org-mac-together-item-get-selected)))
-
-
View
@@ -1,85 +0,0 @@
-;;; org-mac-together.el --- grab and insert links from Together.app, and follow them as well
-;;
-;; Copyright (c) 2010 Anthony Lander
-;;
-;; Author: Anthony Lander <anthony.lander@gmail.com>
-;;
-;;; Commentary:
-;;
-;; This code allows you to grab links to the selected items the
-;; Together.app main window, paste them into an org-mode document, and
-;; follow them using the normal org-mode link opening mechanism.
-;; Together.app is a Mac OS X tool to organize information sold by
-;; Reinvented Software <http://reinventedsoftware.com/>.
-;;
-;; This code is heavily based on org-mac-message.el written by John
-;; Weigley and Christopher Suckling.
-;;
-;;
-;; Installation:
-;;
-;; add ('require org-mac-together) to your .emacs, and then,
-;; optionally, define a key binding like this:
-;;
-;; (add-hook 'org-mode-hook (lambda ()
-;; (define-key org-mode-map (kbd "C-c t") 'org-together-item-insert-selected)))
-;;
-;; Usage:
-;;
-;; Either use the keybinding you defined above or type M-x
-;; org-together-item-insert-selected RET to grab the current selected
-;; items from the main window of Together.app, and insert links to
-;; them into your org-mode document at point.
-;;
-;; To follow a link, use the normal org-mode link following mechanism.
-;;
-;;; Code:
-(require 'org-mac-message)
-
-(org-add-link-type "x-together-item" 'org-together-item-open)
-
-(defun org-together-item-open (uid)
- "Open the given uid, which is a reference to an item in Together"
- (shell-command (concat "open \"x-together-item:" uid "\"")))
-
-
-(defun as-get-selected-togther-items ()
- (do-applescript
- (concat
- "tell application \"Together\"\n"
- "set theLinkList to {}\n"
- "set theSelection to selected items\n"
- "repeat with theItem in theSelection\n"
- "set theLink to (get item link of theItem) & \"::split::\" & (get name of theItem) & \"\n\"\n"
- "copy theLink to end of theLinkList\n"
- "end repeat\n"
- "return theLinkList as string\n"
-"end tell")))
-
-(defun org-together-item-get-selected ()
- (interactive)
- (message "Applescript: Getting Togther items...")
- (let* ((as-link-list (as-get-selected-togther-items))
- (link-list
- (mapcar
- (lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x) (setq x (match-string 1 x))) x)
- (split-string as-link-list "[\r\n]+")))
- split-link URL description orglink orglink-insert rtn orglink-list)
- (while link-list
- (setq split-link (split-string (pop link-list) "::split::"))
- (setq URL (car split-link))
- (setq description (cadr split-link))
- (when (not (string= URL ""))
- (setq orglink (org-make-link-string URL description))
- (push orglink orglink-list)))
- (setq rtn (mapconcat 'identity orglink-list "\n"))
- (kill-new rtn)
- rtn))
-
-(defun org-together-item-insert-selected ()
- (interactive)
- (insert (org-together-item-get-selected)))
-
-(provide 'org-mac-together)
-
-;;; org-mac-together.el ends here

0 comments on commit 519abbb

Please sign in to comment.