On 2025-02-01 18:43, Uwe Brauer via General discussions about Org-mode. wrote:
(BTW do you speak Spanish , since there is some Spanish text in the
files that are attached)

Anyhow.

Let me see if I understand that correctly

     - Your code does not insert
* <2025-02-01>
     But instead
* Some heading
:PROPERTIES:
:CREATED:  [2023-11-17 Fri 19:32]
:END:
    that is also ok, but for the moment I prefer the timestamp in the
    heading, because if I use outline-hide-body I obtain a nice overview
    with the dates.


     - Another problem is that I don't get your code to work for example
       the one in the file  auto-insert-created-timestamp-as-property.org
       gives me

Yes, I speak Spanish :)

To generate dates as you said, you can use the following code [0], on ~man date~ you can find other strftime format constructions, or alternatively, visit this [1]

The scheduled thing [2] had an if for certain conditions where you want that hook to get triggered (that uses specific buffer names that in my case are [2]), for a more simple approach, you might want to experiment with a simpler function [3]

I attach again the script migrate-from-ts-header-to-created-property.org because I got confused; I hope "soon" I could have a git public repo with my emacs config

[0]
#+begin_src emacs-lisp
(defun my/org-add-timestamp-on-heading ()
  (save-excursion
    (org-back-to-heading)
    (org-edit-headline (format-time-string "<%F>"))
    (my/set-property-with-inactive-timestamp "CREATED")))

(add-hook 'org-insert-heading-hook 'my/org-add-timestamp-on-heading 'append)
;; to remove it
;; (remove-hook 'org-insert-heading-hook 'my/org-add-timestamp-on-heading)
#+end_src

[1] https://strftime.org/

[2]

#+begin_src emacs-lisp
(setq my/diary-file "1activity.org")
(setq my/board-file "board.org")
(setq my/proj-file "projects.org")
(setq my/proj-candidates-file "projects-candidates.org")
#+end_src

[3]
#+begin_src emacs-lisp
(defun my/org-heading-insert-scheduled ()
  (save-excursion
    ;; src https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
    (org-schedule nil (format-time-string "[%Y-%m-%d %a]" nil))))

(add-hook 'org-insert-heading-hook 'my/org-heading-insert-scheduled 'append)
#+end_src
**** script: migrate from old heading format
:PROPERTIES:
:CREATED:  [2023-07-24 Mon 03:38]
:CUSTOM_ID: emacsconf_51
:END:

#+name: created on [2023-07-24 Mon 03:38:47]
#+begin_src emacs-lisp
(defun my/migrate-legacy-created-format ()
  (interactive)
  (org-map-entries
   (lambda ()
     (let* ((title (org-entry-get nil "ITEM"))
            (regexp "^\\(.*\\) <\\(20.*\\)>")
            (current-created (org-entry-get (point) "CREATED")))
       (when (string-match regexp title)
         (let ((new-title (match-string 1 title))
               (new-created (match-string 2 title)))
           (if current-created
               (message "Warning: \"%s\" not added as created property" title)
             (progn
               ;; move match to CREATED property
               (org-entry-put (point) "CREATED" (format "[%s]" new-created))
               ;; delete heading text
               (org-edit-headline new-title)))))))
   nil 'file))
#+end_src

Attachment: OpenPGP_0x9D64597C3A982DCA.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to