emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Skim.app support for org-mac-link-grabber.el
@ 2013-05-12 18:29 Daniil Frumin
  2013-05-13  0:39 ` Ivan Andrus
  2013-05-13  6:34 ` Carsten Dominik
  0 siblings, 2 replies; 9+ messages in thread
From: Daniil Frumin @ 2013-05-12 18:29 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1136 bytes --]

Hi, all!

I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 

Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.

What it does:

* Grabs not just the link to file, but a page

* Inserts the selected text as a description, if present. Otherwise
  inserts "<filename>, p. <page #>"

* The shortcut is set to [S]

* Defines a new "skim" link type

It would be interesting to also add some support for importing notes from Skim to org.

Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.

So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.

Cheers.

-- Daniil Frumin

[-- Attachment #2: 0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch --]
[-- Type: application/octet-stream, Size: 5000 bytes --]

From 1326cb78bfcc2111e4fd59789a3960d09cb4a694 Mon Sep 17 00:00:00 2001
From: Daniil <ohwow@cpan.org>
Date: Sun, 12 May 2013 22:11:09 +0400
Subject: [PATCH] Adding Skim.app support to org-mac-link-grabber.el

* The shortcut is set to [S]

* Grabs not just the link to file, but a page

* Inserts the selected text as a description, if present. Otherwise
  inserts "<filename>, p. <page #>"

* Defines a new "skim" link type
---
 contrib/lisp/org-mac-link-grabber.el | 83 ++++++++++++++++++++++++++++++++----
 1 file changed, 75 insertions(+), 8 deletions(-)

diff --git a/contrib/lisp/org-mac-link-grabber.el b/contrib/lisp/org-mac-link-grabber.el
index 0598617..e71fc15 100644
--- a/contrib/lisp/org-mac-link-grabber.el
+++ b/contrib/lisp/org-mac-link-grabber.el
@@ -128,21 +128,28 @@ applications and inserting them in org documents"
   :group 'org-mac-link-grabber
   :type 'boolean)
 
+(defcustom org-mac-grab-Skim-app-p t
+  "Enable menu option [S]kim to grab page links from Skim.app"
+  :tag "Grab Skim.app page links"
+  :group 'org-mac-link-grabber
+  :type 'boolean)
+
 \f
 (defun omlg-grab-link ()
   "Prompt the user for an application to grab a link from, then go grab the link, and insert it at point"
   (interactive)
   (let* ((descriptors `(("F" "inder" org-mac-finder-insert-selected ,org-mac-grab-Finder-app-p)
-						("m" "ail" org-mac-message-insert-selected ,org-mac-grab-Mail-app-p)
-						("a" "ddressbook" org-mac-addressbook-insert-selected ,org-mac-grab-Addressbook-app-p)
-						("s" "afari" org-mac-safari-insert-frontmost-url ,org-mac-grab-Safari-app-p)
-						("f" "irefox" org-mac-firefox-insert-frontmost-url ,org-mac-grab-Firefox-app-p)
-						("v" "imperator" org-mac-vimperator-insert-frontmost-url ,org-mac-grab-Firefox+Vimperator-p)
-						("c" "hrome" org-mac-chrome-insert-frontmost-url ,org-mac-grab-Chrome-app-p)
-						("t" "ogether" org-mac-together-insert-selected ,org-mac-grab-Together-app-p)))
+			("m" "ail" org-mac-message-insert-selected ,org-mac-grab-Mail-app-p)
+			("a" "ddressbook" org-mac-addressbook-insert-selected ,org-mac-grab-Addressbook-app-p)
+			("s" "afari" org-mac-safari-insert-frontmost-url ,org-mac-grab-Safari-app-p)
+			("f" "irefox" org-mac-firefox-insert-frontmost-url ,org-mac-grab-Firefox-app-p)
+			("v" "imperator" org-mac-vimperator-insert-frontmost-url ,org-mac-grab-Firefox+Vimperator-p)
+			("c" "hrome" org-mac-chrome-insert-frontmost-url ,org-mac-grab-Chrome-app-p)
+			("t" "ogether" org-mac-together-insert-selected ,org-mac-grab-Together-app-p)
+			("S" "kim" org-mac-skim-insert-page ,org-mac-grab-Skim-app-p)))
 		 (menu-string (make-string 0 ?x))
 		 input)
-
+    
 	;; Create the menu string for the keymap
 	(mapc '(lambda (descriptor)
 			(when (elt descriptor 3)
@@ -460,6 +467,66 @@ applications and inserting them in org documents"
   (interactive)
   (insert (org-mac-addressbook-item-get-selected)))
 
+;;
+;;
+;; Handle links from Skim.app
+;;
+;; A rewriting of some code originally by Christopher Suckling from org-mac-protocol
+
+(org-add-link-type "skim" 'org-mac-skim-open)
+
+(defun org-mac-skim-open (uri)
+  "Visit page of pdf in Skim"
+  (let* ((page (when (string-match "::\\(.+\\)\\'" uri)
+		 (match-string 1 uri)))
+	 (document (substring uri 0 (match-beginning 0))))
+    (do-applescript
+     (concat
+      "tell application \"Skim\"\n"
+         "activate\n"
+	 "set theDoc to \"" document "\"\n"
+		     "set thePage to " page "\n"
+	 "open theDoc\n"
+	 "go document 1 to page thePage of document 1\n"
+      "end tell"))))
+
+
+(defun as-get-skim-page-link ()
+  (do-applescript
+   (concat
+    "tell application \"Skim\"\n"
+       "set theDoc to front document\n"
+       "set theTitle to (name of theDoc)\n"
+       "set thePath to (path of theDoc)\n"
+       "set thePage to (get index for current page of theDoc)\n"
+       "set theSelection to selection of theDoc\n"
+       "set theContent to contents of (get text for theSelection)\n"
+       "if theContent is missing value then\n"
+          "set theContent to theTitle & \", p. \" & thePage\n"
+       "end if\n"
+       "set theLink to \"skim://\" & thePath & \"::\" & thePage & "
+       "\"::split::\" & theContent\n"
+    "end tell\n"
+    "return theLink as string\n")))
+
+(defun org-mac-skim-get-page ()
+  (interactive)
+  (message "Applescript: Getting Skim page link...")
+  (let* ((url-and-title (as-get-skim-page-link))
+         (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-skim-insert-page ()
+  (interactive)
+  (insert (org-mac-skim-get-page)))
+
+
 \f
 (provide 'org-mac-link-grabber)
 
-- 
1.7.12.4 (Apple Git-37)


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-14  7:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-12 18:29 Skim.app support for org-mac-link-grabber.el Daniil Frumin
2013-05-13  0:39 ` Ivan Andrus
2013-05-13  6:34 ` Carsten Dominik
2013-05-13  9:53   ` Daniel F
2013-05-13 10:54     ` Carsten Dominik
2013-05-13 20:35   ` Daniil Frumin
2013-05-14  4:33     ` Carsten Dominik
2013-05-14  6:18       ` Daniil Frumin
2013-05-14  7:12         ` Carsten Dominik

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).