emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-mac-addressbook.el
@ 2010-03-21 11:38 Alexander Poslavsky
  2010-03-21 17:32 ` org-mac-addressbook.el Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Poslavsky @ 2010-03-21 11:38 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello,

playing around with mac integration and org (using org-mac-protocol) I wrote mac address-book integration. It is slightly based on org-mac-message. It is the first ever lisp and/or applescript I ever wrote, so … but it works.

New hyperlink: [[address:BC70B043-0144-4AC1-9FFA-9D33F04C8B8A:ABPerson][Name]], which, when clicked will open the entry in the address book. It works for both persons as companies.

Adding a link to org is done using org-remember (and quicksilver).

thanks,

Alex

Attached: a diff to getItemMetadata from org-mac-protocol, and a new file called org-mac-addressbook


[-- Attachment #2: getItemMetadata.applescript.diff --]
[-- Type: application/octet-stream, Size: 1651 bytes --]

diff --git a/orgQSLib/getItemMetadata.applescript b/orgQSLib/getItemMetadata.applescript
index 14b201e..6e1f089 100644
--- a/orgQSLib/getItemMetadata.applescript
+++ b/orgQSLib/getItemMetadata.applescript
@@ -78,7 +78,11 @@ on getItemMetadata(theProtocol, theApp)
 											if (theApp as string) = "Finder" then
 												linkFinder(theProtocol, theApp)
 											else
-												linkApplication(theProtocol, theApp)
+												if (theApp as string) = "Address Book" then
+													linkAddressbook(theProtocol, theApp)
+												else
+													linkApplication(theProtocol, theApp)
+												end if
 											end if
 										end if
 									end if
@@ -404,6 +408,29 @@ on linkFinder(theProtocol, theApp)
 	set theLink to theProtocol & escScheme & escPath & "/" & escTitle & "/" & escShortTitle & ":" & escApp
 end linkFinder
 
+
+on linkAddressbook(theProtocol, theApp)
+	tell application "Address Book"
+		set theScheme to "address:"
+		set AllContacts to selection
+		if number of items in AllContacts = 1 then
+			set one_contact to item 1 of AllContacts
+			set theID to id of one_contact
+			set theName to name of one_contact
+		else
+			tell application "System Events"
+				activate
+				display dialog "Error: Choose one contact"
+			end tell
+		end if
+	end tell
+	
+	set escID to encodeURIComponent(theID)
+	set escName to encodeURIComponent(theName)
+	set escScheme to encodeURIComponent(theScheme)
+	set theLink to theProtocol & escScheme & escID & "/" & escName & ":" & escApp
+end linkAddressbook
+
 on linkApplication(theProtocol, theApp)
 	tell application (theApp as string)
 		set theScheme to "file:/"

[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




[-- Attachment #4: org-mac-addressbook.el --]
[-- Type: application/octet-stream, Size: 1289 bytes --]

;;;; org-mac-addressbook.el --- Links to Apple Address Book entries from within Org-mode

;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.

;; Author: Alexander Poslavsky <alexander.poslavsky at gmail dot com>

;;;; Commentary:
;; This file implements links from the Apple Address Book entries from within org-mode
;; Org-mode does not load this module by default - if you would actually like
;; this to happen then configure the variable `org-modules'.

;;;; Code:
(require 'org)

(org-add-link-type "address" 'org-mac-address-open)

(defun org-mac-address-open (address-id)
  "Visit the addresbook-entry with the given address-id"
  (open-addressbook address-id))

(defun open-addressbook (address-id)
"Applescript to open correct address-book entry"
(ns-do-applescript (concat
   "set theID to \"" address-id "\"\n"
   "tell application \"Address Book\"\n"
	"set myPerson to first person whose id is theID\n"
	"set myName to name of first person whose id is theID\n"
	"set thePeople to selection\n"
   "end tell\n"

   "tell application \"System Events\"\n"
   "activate\n"
   "try\n"
      "open location \"addressbook\:\/\/\" \& theID\n"
   "on error\n"
      "display dialog \"no matching contact found\"\n"
   "end try\n"
   "end tell"
)))

(provide 'org-mac-addressbook)

[-- Attachment #5: Type: text/plain, Size: 3 bytes --]





[-- Attachment #6: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-03-23  0:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-21 11:38 org-mac-addressbook.el Alexander Poslavsky
2010-03-21 17:32 ` org-mac-addressbook.el Carsten Dominik
2010-03-22 23:51   ` org-mac-addressbook.el Christopher Suckling
2010-03-23  0:04     ` org-mac-addressbook.el Alexander Poslavsky

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).