Folder: Devops Web page: www.yandex.ru E-mail message: (вторник, 12 декабря 2017 г.) заявка 12044970 (Иванов Иван Иванович)
(if (eq system-type 'darwin)
(use-package org-mac-link
:config
;; key to grab mac links
(define-key org-mode-map (kbd "C-c g") 'org-mac-grab-link)
;; Hacks
(defun org-mac-safari-insert-frontmost-url ()
(interactive)
(insert (format "Web page: %s\n" (org-mac-safari-get-frontmost-url)))
)
(defun org-mac-outlook-message-insert-selected ()
"Insert a link to the messages currently selected in Microsoft Outlook.app.
This will use AppleScript to get the message-id and the subject
of the active mail in Microsoft Outlook.app and make a link out
of it."
(interactive)
(insert (format "E-mail message: %s\n" (org-mac-outlook-message-get-links "s")))
)
(defun org-mac-finder-insert-selected ()
(interactive)
(insert (format "Folder or file: %s\n" (org-mac-finder-item-get-selected)))
)
(defun org-mac-firefox-insert-frontmost-url ()
(interactive)
(insert (format "Web page: %s\n" (org-mac-firefox-get-frontmost-url))))
(defun org-mac-chrome-insert-frontmost-url ()
(interactive)
(insert (format "Web page: %s\n" (org-mac-chrome-get-frontmost-url))))
(defun org-mac-message-insert-selected ()
"Insert a link to the messages currently selected in Mail.app.
This will use AppleScript to get the message-id and the subject of the
active mail in Mail.app and make a link out of it."
(interactive)
(insert (format "E-mail message: %s\n" (org-mac-message-get-links "s"))))
(defun org-as-get-selected-mail ()
"AppleScript to create links to selected messages in Mail.app."
(do-applescript
(concat
"tell application \"Mail\"\n"
"set theLinkList to {}\n"
"set theSelection to selection\n"
"repeat with theMessage in theSelection\n"
"set theID to message id of theMessage\n"
"set theSender to extract name from sender of theMessage\n"
"set theDateReceived to (date received) of theMessage\n"
;; "set theDate to (format date (theDateReceived) with format \"%m, %d %Y\")\n"
;; "set theLink to \"message://\" & theID & \"::split::\" & theDate & \"(\" & theDateReceived & \") \" & theSubject & \" (\" & theSender & \")\" \n"
"set theSubject to subject of theMessage\n"
"set theLink to \"message://\" & theID & \"::split::\" & \"(\" & theDateReceived & \") \" & theSubject & \" (\" & theSender & \")\" \n"
"if (theLinkList is not equal to {}) then\n"
"set theLink to \"\n\" & theLink\n"
"end if\n"
"copy theLink to end of theLinkList\n"
"end repeat\n"
"return theLinkList as string\n"
"end tell")))
(defun org-as-get-selected-outlook-mail ()
"AppleScript to create links to selected messages in Microsoft Outlook.app."
(do-applescript
(concat
"tell application \"/Applications/Microsoft Outlook.app\"\n"
"set msgCount to count current messages\n"
"if (msgCount < 1) then\n"
"return\n"
"end if\n"
"set theLinkList to {}\n"
"set theSelection to (get current messages)\n"
"repeat with theMessage in theSelection\n"
"set theID to id of theMessage as string\n"
"set theURL to \"mac-outlook:\" & theID\n"
"set theSubject to subject of theMessage\n"
"set theSender to sender of theMessage\n"
;; "set theDateReceived to date string of (get time sent of item 1 of theSelection)\n"
"set theDateReceived to date string of (get time sent of theMessage)\n"
;; "set theLink to theURL & \"::split::\" & theSubject & \"\n\"\n"
"set theLink to theURL & \"::split::\" & \"(\" & theDateReceived & \") \" & theSubject & \" (\" & name of theSender & \")\" \n"
"copy theLink to end of theLinkList\n"
"end repeat\n"
"return theLinkList as string\n"
"end tell")))
(defun org-mac-outlook-message-open (msgid)
"Open a message in Outlook"
(do-applescript
(concat
"tell application \"/Applications/Microsoft Outlook.app\"\n"
(format "open message id %s\n" (substring-no-properties msgid))
"activate\n"
"end tell")))
(defun org-mac-outlook-message-get-links (&optional select-or-flag)
"Create links to the messages currently selected or flagged in Microsoft Outlook.app.
This will use AppleScript to get the message-id and the subject of the
messages in Microsoft Outlook.app and make a link out of it.
When SELECT-OR-FLAG is \"s\", get the selected messages (this is also
the default). When SELECT-OR-FLAG is \"f\", get the flagged messages.
The Org-syntax text will be pushed to the kill ring, and also returned."
(interactive "sLink to (s)elected or (f)lagged messages: ")
(setq select-or-flag (or select-or-flag "s"))
(message "Org Mac Outlook: searching mailboxes...")
(let* ((as-link-list
(if (string= select-or-flag "s")
(org-as-get-selected-outlook-mail)
(if (string= select-or-flag "f")
(org-sh-get-flagged-outlook-mail)
(error "Please select \"s\" or \"f\""))))
(message "1")
(link-list
(mapcar
(lambda (x) (if (string-match "\\`\"\\(.*\\)\"\\'" x) (setq x (match-string 1 x))) x)
(split-string as-link-list "[\r\n]+")))
(message "2")
split-link URL description orglink orglink-insert rtn orglink-list)
(while link-list
(setq split-link (split-string (pop link-list) "::split::"))
(setq URL (car split-link))
(setq description (cadr split-link))
(when (not (or (string= URL "") (string= URL "\"")))
(if (string= (substring URL 0 1) "\"")
(setq URL (substring URL 1 nil)))
(message URL)
(setq orglink (org-make-link-string URL description))
(push orglink orglink-list)))
(setq rtn (mapconcat 'identity orglink-list "\n"))
(kill-new rtn)
rtn))
;; )
)
)