emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Alexander Poslavsky <alexander.poslavsky@gmail.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: org-mac-addressbook.el
Date: Sun, 21 Mar 2010 12:38:38 +0100	[thread overview]
Message-ID: <A325CB14-8FF9-47CD-A455-71E38F194249@gmail.com> (raw)

[-- 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

             reply	other threads:[~2010-03-21 11:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-21 11:38 Alexander Poslavsky [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A325CB14-8FF9-47CD-A455-71E38F194249@gmail.com \
    --to=alexander.poslavsky@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).