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

* Re: org-mac-addressbook.el
  2010-03-21 11:38 org-mac-addressbook.el Alexander Poslavsky
@ 2010-03-21 17:32 ` Carsten Dominik
  2010-03-22 23:51   ` org-mac-addressbook.el Christopher Suckling
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2010-03-21 17:32 UTC (permalink / raw)
  To: Alexander Poslavsky, Christopher Suckling; +Cc: emacs-orgmode

Hi Alexander,

this is awesome, thank you very much.

I would like to integrate this into org-mac-message.el - I don't
think it makes much sense to put this into a separate file.

This would, however, mean that the code becomes part of Emacs,
and that I need you to sign the papers with the FSF.  Would you
be willing to do this?

Christopher, could I ask you to verify this code and work together
with Alexander on integrating it (if Alexander agrees, of course).

Thanks.

- Carsten

On Mar 21, 2010, at 12:38 PM, Alexander Poslavsky wrote:

> 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
>
> <getItemMetadata.applescript.diff>
>
> <org-mac-addressbook.el>
>
>
> _______________________________________________
> 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

- Carsten

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

* Re: org-mac-addressbook.el
  2010-03-21 17:32 ` org-mac-addressbook.el Carsten Dominik
@ 2010-03-22 23:51   ` Christopher Suckling
  2010-03-23  0:04     ` org-mac-addressbook.el Alexander Poslavsky
  0 siblings, 1 reply; 4+ messages in thread
From: Christopher Suckling @ 2010-03-22 23:51 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode, Christopher Suckling

On Sun, 21 Mar 2010 18:32:17 +0100, Carsten Dominik <carsten.dominik@gmail.com> wrote:
>
> this is awesome, thank you very much.

Quite so.

> I would like to integrate this into org-mac-message.el - I don't
> think it makes much sense to put this into a separate file.

My inclination is to integrate it into the almost complete
org-mac-protocol. It seems to be working robustly on my system, but
could use some better error handling at the AppleScript level in case
things do go wrong.

http://github.com/claviclaws/org-mac-protocol

That way there is one consistent method of sending data to orgmode from
OS X applications.

>
> Christopher, could I ask you to verify this code and work together
> with Alexander on integrating it (if Alexander agrees, of course).
>

I'll take a closer look in the next couple of days.

Best, Christopher

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

* Re: org-mac-addressbook.el
  2010-03-22 23:51   ` org-mac-addressbook.el Christopher Suckling
@ 2010-03-23  0:04     ` Alexander Poslavsky
  0 siblings, 0 replies; 4+ messages in thread
From: Alexander Poslavsky @ 2010-03-23  0:04 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 955 bytes --]


On Mar 23, 2010, at 12:51 AM, Christopher Suckling wrote:
<snip>
> 
> My inclination is to integrate it into the almost complete
> org-mac-protocol. It seems to be working robustly on my system, but
> could use some better error handling at the AppleScript level in case
> things do go wrong.
> 
> http://github.com/claviclaws/org-mac-protocol
> 
> That way there is one consistent method of sending data to orgmode from
> OS X applications.
> 
>> 
>> Christopher, could I ask you to verify this code and work together
>> with Alexander on integrating it (if Alexander agrees, of course).
>> 
> 
> I'll take a closer look in the next couple of days.
> 
> Best, Christopher

Sounds good to me. I have been looking at other apps that I use as well, and I would like to integrate netnewswire as well, it's applescript is fine. Colloquy is the last app I regularly use, but I have not yet found out how to script that.

thanks,
alex

[-- Attachment #1.2: Type: text/html, Size: 1489 bytes --]

[-- Attachment #2: 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	[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).