emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to export property values of agenda selection?
@ 2013-03-26 17:51 Karl Maihofer
  2013-03-26 22:53 ` Christian Moe
  0 siblings, 1 reply; 6+ messages in thread
From: Karl Maihofer @ 2013-03-26 17:51 UTC (permalink / raw)
  To: emacs-orgmode

I'd like to manage some distribution (mailing) lists in Org. This works great
using tags and agenda column view.

I have an Org file like this:

#+COLUMNS: %25ITEM %30EMAIL %20TAGS

* Peter Mayer						      :topic1:topic2:
:PROPERTIES:
:EMAIL:    peter@mayer.com
:END:
* Karl August					       :topic1:topic2:topic4:
:PROPERTIES:
:EMAIL: karl@august.com
:END:
* Peter Müller							     :topic1:
:PROPERTIES:
:EMAIL:    peter@mueller.com
:END:

When I want to write an email about topic2 I use the agenda to display online
the entries tagged with "topic2":

Headlines with TAGS match: topic2
Press `C-u r' to search again with new search string
  verteiler:  Peter Mayer                                        :topic1:topic2:
  verteiler:  Karl August                                 :topic1:topic2:topic4:

I now can use column view in the agenda to display the email addresses and even
adjust some entries.

What I'd like to do now is to export a comma-separated list of the email
addresses of the entries in the agenda selection:
"peter@mayer.com,karl@august.com" in the case above.

Does anybody have an idea how to solve this?

Thanks,
Karl

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

* Re: How to export property values of agenda selection?
  2013-03-26 17:51 How to export property values of agenda selection? Karl Maihofer
@ 2013-03-26 22:53 ` Christian Moe
  2013-03-27 18:08   ` Karl Maihofer
  2013-04-06 12:48   ` Karl Maihofer
  0 siblings, 2 replies; 6+ messages in thread
From: Christian Moe @ 2013-03-26 22:53 UTC (permalink / raw)
  To: Karl Maihofer; +Cc: emacs-orgmode


Karl Maihofer writes:
> * Peter Mayer						      :topic1:topic2:
> :PROPERTIES:
> :EMAIL:    peter@mayer.com
> :END:
> * Karl August					       :topic1:topic2:topic4:
> :PROPERTIES:
> :EMAIL: karl@august.com
> :END:
> * Peter Müller							     :topic1:
> :PROPERTIES:
> :EMAIL:    peter@mueller.com
> :END:
[...]
> What I'd like to do now is to export a comma-separated list of the email
> addresses of the entries in the agenda selection:
> "peter@mayer.com,karl@august.com" in the case above.

I don't know how to do it from the agenda selection, but here's a pretty
simple way to do it in the document buffer using Babel:

#+NAME: list2csv
#+BEGIN_SRC emacs-lisp :var match="topic2"
      (mapconcat 'identity 
                 (org-map-entries 
                  '(org-entry-get (point) "EMAIL") 
                  match nil)
                 ",")
#+END_SRC

Now you can use a CALL line with a tags match as a parameter, like

#+CALL: list2csv(match="topic2")

to get

#+RESULTS: list2csv(match="topic2")
: peter@mayer.com,karl@august.com

Yours,
Christian

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

* Re: How to export property values of agenda selection?
  2013-03-26 22:53 ` Christian Moe
@ 2013-03-27 18:08   ` Karl Maihofer
  2013-04-06 12:48   ` Karl Maihofer
  1 sibling, 0 replies; 6+ messages in thread
From: Karl Maihofer @ 2013-03-27 18:08 UTC (permalink / raw)
  To: emacs-orgmode

Christian Moe <mail <at> christianmoe.com> writes:
> I don't know how to do it from the agenda selection, but here's a pretty
> simple way to do it in the document buffer using Babel:

Christian, thanks a lot! That does the job.

Kind regards,
Karl

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

* Re: How to export property values of agenda selection?
  2013-03-26 22:53 ` Christian Moe
  2013-03-27 18:08   ` Karl Maihofer
@ 2013-04-06 12:48   ` Karl Maihofer
  2013-04-07  7:06     ` Christian Moe
  1 sibling, 1 reply; 6+ messages in thread
From: Karl Maihofer @ 2013-04-06 12:48 UTC (permalink / raw)
  To: emacs-orgmode

Christian Moe <mail <at> christianmoe.com> writes:
> I don't know how to do it from the agenda selection, but here's a pretty
> simple way to do it in the document buffer using Babel:
> 
> #+NAME: list2csv
> #+BEGIN_SRC emacs-lisp :var match="topic2"
>       (mapconcat 'identity 
>                  (org-map-entries 
>                   '(org-entry-get (point) "EMAIL") 
>                   match nil)
>                  ",")
> #+END_SRC
> 
> Now you can use a CALL line with a tags match as a parameter, like
> 
> #+CALL: list2csv(match="topic2")
> 
> to get
> 
> #+RESULTS: list2csv(match="topic2")
> : peter <at> mayer.com,karl <at> august.com

Does anybody know how to get the results via Emacs batch mode on the command
line? I'd like to embed the results in a webpage.

The following is my starting point and of course terribly wrong and it
doesn't work. It's hard for me to find documentation (that I understand).

$ emacs -batch -l ~/.emacs -eval (progn 
   (find-file \"~/test.org\")
   (org-babel-execute-src-block 'list2csv)
   (kill-buffer))"

Thanks,
Karl

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

* Re: How to export property values of agenda selection?
  2013-04-06 12:48   ` Karl Maihofer
@ 2013-04-07  7:06     ` Christian Moe
  2013-04-08  9:00       ` Karl Maihofer
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Moe @ 2013-04-07  7:06 UTC (permalink / raw)
  To: Karl Maihofer; +Cc: emacs-orgmode


Hi,

If I recall, you have a bunch of tagged headings with EMAIL properties,
and you want to extract a comma-separated list of email addresses based
on tag matching. I posted an example of one approach, using a Babel block
to put results inline.

I'm not quite clear on your use case / desired result now. Why do you
want results through batch mode on the command line in order to embed
them in a webpage? Embed how? Is this something you could perhaps do
simply by exporting from Org to HTML? 

Yours,
Christian

> Does anybody know how to get the results via Emacs batch mode on the command
> line? I'd like to embed the results in a webpage.
>
> The following is my starting point and of course terribly wrong and it
> doesn't work. It's hard for me to find documentation (that I understand).
>
> $ emacs -batch -l ~/.emacs -eval (progn 
>    (find-file \"~/test.org\")
>    (org-babel-execute-src-block 'list2csv)
>    (kill-buffer))"
>
> Thanks,
> Karl

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

* Re: How to export property values of agenda selection?
  2013-04-07  7:06     ` Christian Moe
@ 2013-04-08  9:00       ` Karl Maihofer
  0 siblings, 0 replies; 6+ messages in thread
From: Karl Maihofer @ 2013-04-08  9:00 UTC (permalink / raw)
  To: emacs-orgmode

Hi Christian,

Christian Moe <mail <at> christianmoe.com> writes:
> I'm not quite clear on your use case / desired result now. Why do you
> want results through batch mode on the command line in order to embed
> them in a webpage? Embed how? Is this something you could perhaps do
> simply by exporting from Org to HTML? 

Thanks for your mail. I found a (not so quick but very dirty) way to do what
I want. Just to explain:

The first step was the management of distribution lists withhin emacs.  In
the second step I wanted to make the distribution lists also available via
Web.  What I did now is to use a combination of php, emacs batch mode and
agenda views, shellscript and perl:

In my index.php I call a shell script:
=====================================

<!-- ;-separated list of email addresses -->
<pre><?php echo shell_exec("emacs-export-distribution-list.sh"); ?></pre>

emacs-export-distribution-list.sh
==================================

# Export Agenda View and write to file
emacs -batch -l ~/.emacs -eval '(org-batch-agenda "1")' | sed '1d' | sed
'1d' > distribution_list.txt

# Extract email adresses
perl -wne 'while(/[\w\.]+@[\w\.]+\w+/g){print "$&; "}' distribution_list.txt

Emacs configuration
====================

(setq org-agenda-custom-commands
  (quote (("1" "Distribution List" tags "tag1+tag2"
     ((org-agenda-prefix-format
          '((tags  . "%-40:(km/get-properties) ; ")))
      (org-use-tag-inheritance nil))))))

And the function:

(defun km/get-properties ()
  (concat
    (org-entry-get (point) "EMAIL")))


In emacs I could not find a way to extract only the email addresses in an
agenda view. So it was a good idea to use the following in the buffer as you
suggested:

#+NAME: list2csv
#+BEGIN_SRC emacs-lisp :var match="tag1+tag2"
      (mapconcat 'identity 
                 (org-map-entries 
                  '(org-entry-get (point) "EMAIL") 
                  match nil)
                 ",")
#+END_SRC

But for the webpage I could use Perl to further process an agenda view.  And
since I knew how to get an agenda view exported using emacs batch mode, this
was the hack I was looking for.

Perhaps not very professional, but it works. ;-)

Thanks again for your help!

Karl

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

end of thread, other threads:[~2013-04-08 16:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-26 17:51 How to export property values of agenda selection? Karl Maihofer
2013-03-26 22:53 ` Christian Moe
2013-03-27 18:08   ` Karl Maihofer
2013-04-06 12:48   ` Karl Maihofer
2013-04-07  7:06     ` Christian Moe
2013-04-08  9:00       ` Karl Maihofer

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