From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id WFCqOfvwH1/8QwAA0tVLHw (envelope-from ) for ; Tue, 28 Jul 2020 09:33:47 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CHtHNfvwH18cXwAAbx9fmQ (envelope-from ) for ; Tue, 28 Jul 2020 09:33:47 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8164B940416 for ; Tue, 28 Jul 2020 09:33:46 +0000 (UTC) Received: from localhost ([::1]:37084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k0LzU-0006Q4-Uh for larch@yhetil.org; Tue, 28 Jul 2020 05:33:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0Lz9-0006Px-4E for emacs-orgmode@gnu.org; Tue, 28 Jul 2020 05:33:23 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:35767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k0Lz6-00024u-PC for emacs-orgmode@gnu.org; Tue, 28 Jul 2020 05:33:22 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 91DF312D9; Tue, 28 Jul 2020 05:33:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 28 Jul 2020 05:33:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eml.cc; h=from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=fm3; bh= I49/DttpkQ6FWfcmsrko9KSEvCKpxdmIKem2K6LEKI8=; b=E7RulgYDkrS19bYl at1rimkenYN2iUi2qbsBXW1CCHJtGHHKfEY+pHEK576rG2YL0bqQaIXSGNzbJk8P jE0pGDODz7vx9t6C5AHEBgJRjTTH/S1LHDqmD/+0S4cyccnUra6C0qwR4Yc+IbzN aeb8QoWhw9kclEVRLX7zuclV281w2lhcwh0a5+kBurjwHc/OpN8NStHOVtMXwBR9 m6XpX5Qdzn6PxC9WAWxst2AWpbYaxOFEIGjafiERa/ncYhZDmccghD9MFIq+TpvQ Hgs0MXP+rKJBNjCbgvCqnY5559ByErTp/eYWBM/KPh6ubTZCxjhx9o8vqokvEY1K q+ylNQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=I49/DttpkQ6FWfcmsrko9KSEvCKpxdmIKem2K6LEK I8=; b=VA0UE9DPdsy0e5PkF+xr+uDlxpNo0XPUV0gHCmVD7+cKgEnZXf9S64gq5 lkZhB+IQc04oOFV4ObUKrAh8FhPHgbsuouH4+G51NarzFAKhhSmZtrSjGibOUT43 m+1skIMi/FmY1XVbTKIE4DzqiZH+iGEQ83pu7bBwDxzE8WJrzC/O2TJUEqV3CDXT yAKjJ0IChvn1gmM91rivh295yFZBHAm/a2tBFwtoKHXSTZWYnkZYjZGs8xeOp3q1 RHm4NviIQCLMhK/cvUuFqcIlAj3ns9Q8vPIduPl7jyjghMmwKsSrbQzxEX1yntEN qroRTSwjUExaQMzlNiQ9mhJ7mVK8g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedriedvgddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdeftddmnecujfgurhephffvuf ffkfgjfhgggfgtsehtufertddttddvnecuhfhrohhmpefoihhkhhgrihhlucfukhhorhii hhhinhhskhhiihcuoehmshhkohhriihhihhnshhkihihsegvmhhlrdgttgeqnecuggftrf grthhtvghrnhepudevudfgveeigffghfetueeileekgfevieekjefhffeludeutdfhffef ueegleegnecuffhomhgrihhnpehinhhvvghnthgrrhdrohhrghdpsghufhhfvghrrdhorh hgpdgtrghpthhurhgvqdhinhhvvghnthgrrhdrohhrghenucfkphepkeekrddvudehrddu tdefrdduleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehmshhkohhriihhihhnshhkihihsegvmhhlrdgttg X-ME-Proxy: Received: from trex230.localnet (unknown [88.215.103.19]) by mail.messagingengine.com (Postfix) with ESMTPA id 5D3E83280065; Tue, 28 Jul 2020 05:33:16 -0400 (EDT) From: Mikhail Skorzhinskii To: emacs-orgmode@gnu.org Subject: Re: Capture with (moving) attachment? Date: Tue, 28 Jul 2020 11:28:37 +0200 Message-ID: <2956402.ksTVMsbfjo@trex230> In-Reply-To: <874kpz8f54.fsf@passepartout.tim-landscheidt.de> References: <874kpz8f54.fsf@passepartout.tim-landscheidt.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: pass client-ip=64.147.123.20; envelope-from=mskorzhinskiy@eml.cc; helo=wout4-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/28 05:33:18 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim Landscheidt Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=eml.cc header.s=fm3 header.b=E7RulgYD; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=VA0UE9DP; dmarc=pass (policy=none) header.from=eml.cc; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.29 X-TUID: mOCQyEf8rIQ6 Hi Tim, I tried to solve the similar problem and come up with the solution with external script to do this. This is basically only tested in Linux with KDEv5 environment, but could be extended to any other DE or to work solely in emacs. Anyway, the idea of the solution is to provide an interface to the graphical file manager, so you can select files and just "send them" to org-mode. For this I wrote elisp function that do the attaching on files you provided, then a script that pass arguments to this function via emacslcient and then a module for file manager for menu to appear. 1. Elsip function for the attaching: (defun org-user/move-to-file-storage (files) "Move FILES at my file system to annex/org file storage." (save-excursion (let ((org-capture-templates org-file-capture-templates)) ;; << don't use org-file-capture-template if you don't want separate capture templates variable for this (org-capture)) ;; Create as many new headings as it need to be created (when (> (length files) 1) (save-excursion (org-clone-subtree-with-time-shift (- (length files) 1) '(4)))) ;; Edit these headings and attach files to them (dolist (file files) (when (file-exists-p file) ;; Just some sane name should be enough (org-edit-headline (concat "File: " (file-name-nondirectory file))) ;; Attach file to the storage room (org-attach-attach file nil 'mv) ;; Edit headline once again with the stored file (let* ((attach-dir (org-attach-dir)) (files (org-attach-file-list attach-dir)) (file (pop files))) (org-edit-headline (format "[[attachment:%s][%s]]" file (org-get-heading t t t t)))) ;; Go to the next free heading (org-next-visible-heading 1))) ;; Make sure that we didn't cancel capture with file that was already moved (org-capture-finalize) ;; Go to the file if we want to say something about it (org-capture-goto-last-stored) ;; Save buffer just in case (save-buffer))) Function implementation is very far from ideal, but it is working to some extent. There is a bug with this function: it inserts one empty headline. Should be easy to fix, sorry about that. 2. Define your capture templates Just like the normal capture templates. (setq org-file-capture-templates ... ) Now calling this function externally will attach files you provided, save org buffers immediately after and leave the frame open on last attached item. Every attached file will have separate heading. And every heading will be a link to the attached file. 3. Store this script somewhere in your $PATH #!/bin/bash # Author: Mikhail Skorzhinskii # # Description: Attach file to the org-mode file storage files= for file in "$@"; do files="${files} \"${file}\"" done; emacsclient -a "" -c -F '((name . "doom-capture"))' \ -e "(org-user/move-to-file-storage (list ${files}))" If you save it as "org-attach-files.sh" then you can call it like org-attach-files.sh file1 file2 file3 But make sure to pass absolute paths, as emacs executable will probably operating in different directory. I personally don't care as file manager always call it with full paths. But easy to fix with readlink -e call. (i.e. file=`readlink -e ${file}` before putting it to ${files}. 4. Place this module to .local/share/kservices5/ServiceMenus/emacs.desktop End name can be anything of course. [Desktop Entry] Type=Service ServiceTypes=KonqPopupMenu/Plugin MimeType=all/all; Actions=org-attach-mv; X-KDE-Priority=TopLevel [Desktop Action org-attach-mv] Name=Send to git-annex Exec=emacs-org-attach-file %U Icon=cloud-download This should work in KDE files managers (like Dolphin). Right-click the file and you will have "Send to git annex" menu item. Mikhail Skorzhinskii On Wednesday, July 22, 2020 11:48:24 PM CEST Tim Landscheidt wrote: > Hi, > > I have a capture template to file items to a list: > | ("i" "inventory" entry > | > | (file "~/Desktop/Agenda/Inventar.org") > | "* %^{Name}" :immediate-finish t) > > Currently, when I want to file an item with an associated > image, I open the directory of the images with dired, visit > the image file, use the capture to add an item, kill the im- > age buffer, use M-0 w in dired to copy the file's name, > switch to the org file, use C-c C-a m to attach the image by > moving the file, and then switch back to the dired buffer. > Lather, rinse, repeat, until the directory with the images > is empty. > > What I want to do instead is open the image file (via dir- > ed), have the capture do the attaching by itself (if it is > called in an image-mode buffer) and then kill the image > buffer. (Emacs does not care if the file associated with > the buffer is deleted in the mean time.) > > First idea was to use %(EXP) to set > org-capture-after-finalize-hook to attach the file, but that > hook is called in the original (image) buffer. > org-capture-before-finalize-hook on the other hand is called > in a CAPTURE-Inventar.org buffer (with no associated file), > same with org-capture-prepare-finalize-hook. (I also would > like to perform the attaching only *after* the item has suc- > cessfully been filed to avoid misfiling/deleting image > files.) > > There are other ways to achieve this in this particular case > (capture, visit the org file, go to (point-max), > (org-attach-attach file nil 'mv), maybe even replace capture > with an (insert (format "* %s\n" (read-string)))), but are > there general solutions for this issue that will work, well, > more generally? > > TIA, > Tim