Using automation for my note taking process
When I’m not at my computer and want to take a note, I usually send myself an email. But the big issue I have with this process is that I never move the note out of the email app later.
Triggered by my current book How to Take Smart Notes, I started a slip-box, and I think it helps me when my notes automatically get added there. So I wrote an AppleScript which the Mail program can call from a rule.
To detect if the mail is a note, it needs to start with the right marker word and be sent from my email address.
The uncompiled script needs to be added to the following folder: ~/Library/Application\ Scripts/com.apple.mail/
Here is the code of my script:
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
set the message_count to the count of these_messages
repeat with i from 1 to the message_count
set this_message to item i of these_messages
set msg_attr to {this_messageid:message id, this_subject:subject, this_content:content, has_attachments:mail attachments} of this_message
set source_dest to "message://%3c" & (this_messageid of msg_attr) & "%3e"
set source_link to "[Source Email](" & source_dest & ")"
if msg_attr's has_attachments ≠ {} then
set msg_attr's has_attachments to "Yes"
else
set msg_attr's has_attachments to "No"
end if
set yaml_header to "---" & return & "tags: [#inbox]" & return & "source: " & source_dest & return & "---" & return
set this_story to yaml_header & "# " & (this_subject of msg_attr) & return & return & (this_content of msg_attr) & return & return & source_link & return & "Has attachment: " & (has_attachments of msg_attr)
-- Place the path to your location (folder) on the next line:
set brainPath to "<PATH_TO_LOCATION>/Brain"
set this_file to ((POSIX file brainPath) as string) & timestamp() & ".md"
my write_to_file(this_story, this_file, true)
end repeat
end perform mail action with messages
end using terms from
on timestamp()
set {year:yr, month:mn, day:dy, hours:h, minutes:m, seconds:s} to (current date)
return (yr as text) & pad(mn as integer) & pad(dy) & pad(h) & pad(m) & pad(s)
end timestamp
on pad(v)
return text -2 thru -1 of ((v + 100) as text)
end pad
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof as «class utf8»
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
The only change you need to make is on line 20 in the script and change the variable brainPath to the right path to the folder where the file will be created.
Comments
How to respond
Write your comment on your on page and link it to this page with the following link:
https://vmac.ch/posts/2021-06-03-using-automation-for-my-note-taking-process/
Then insert the permalink to your post into the form below and submit it.
Alternatively you can reach me by email to: comment@vmac.ch