Skip to content

Instantly share code, notes, and snippets.

@sirtimbly
Created November 1, 2016 02:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirtimbly/dba52edd29163589a8fef013e9c8588d to your computer and use it in GitHub Desktop.
Save sirtimbly/dba52edd29163589a8fef013e9c8588d to your computer and use it in GitHub Desktop.
Plain Text Productivity - Airmail email client messages become new tasks in a text file
-- Create a new task based on the currently selected message in Airmail
-- When Script is run (I suggest FastScripts https://red-sweater.com/fastscripts/) A new line will be added to the taskpaper file of your choice.
-- Quite a lot modified to input text into a plain text file like used by taskpaper. Originally based somewhere back in time on Efficient Computing's AppleScript: http://efficientcomputing.commons.gc.cuny.edu/2012/03/17/copy-email-message-in-mail-app-to-evernote-applescript/
set theTaskFile to "/Users/tbendt/Dropbox/_Tim/Projects/_tasks/projects.taskpaper"
tell application "Airmail 2"
--get selected messages
set theSelection to selected messages
--loop through all selected messages
repeat with theMessage in theSelection
--get information from message
set theMessageDate to short date string of (get current date)
set theMessageSender to the sender of the theMessage
set theMessageSubject to the subject of the theMessage
set theMessageContent to the content of the theMessage
set theMessageURL to selectedMessageUrl
--import message to text file
my WriteLog("- resolve: " & theMessageSubject & " from " & (word 1 of theMessageSender) & " " & (character 1 of word 2 of theMessageSender) & "." & " @due(" & theMessageDate & ")")
end repeat
end tell
on WriteLog(the_text)
set this_story to the_text
--set this_file to (((path to desktop folder) as text) & "test.txt")
set this_file to (POSIX file theTaskFile)
my prepend_to_file(this_story, this_file)
end WriteLog
on prepend_to_file(this_data, target_file) -- (string, file path as string, boolean)
try
--set the target_file to the target_file as text
open for access target_file
set fileContents to (read target_file from 7 to eof)
close access target_file
set the open_target_file to ¬
open for access file target_file with write permission
set newInboxData to "Inbox:" & return & " " & this_data
--set fileContent to searchAndReplace(fileContents, "Inbox:", newInboxData)
--write fileContents to the open_target_file starting at 0
write newInboxData & fileContents to the open_target_file starting at 0
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end prepend_to_file
@bobsica
Copy link

bobsica commented Dec 22, 2016

I tried this with Airmail 3 & TP 3, and get the error:

 > error "The variable theTaskFile is not defined." number -2753 from “theTaskFile"

I’m sure the path I specified in line 4 is correct? Do you know what the problem is?

@sirtimbly
Copy link
Author

One possibility is that you used a ~/ in your path — which applescript doesn't expand correctly for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment