View Single Post
The reason that I'm working on a replacement for Clip-o-tron is due to it's limitations within Mail actions. I'd like in one workflow to be able to both send the email to an archive within Mail and at the same time post a link and text in OF. If Clip-o-tron could be instructed to do different actions depending on 'shortcuts' or small AS snippets I be dropping my version right away.

Here is the AppleScript. The code is still preliminary - I'm learning AS at the same time. Would like to be able to both handle Actions and Waiting for in the same workflow - depending on the Context selected in the Quick Note.


set MAIL_ACTION_TARGET to "Action"

tell application "Mail"
		set these_selections to selection
		set the current_mail to item 1 of the these_selections
		set theSubject to subject of current_mail
		set umid to message id of the current_mail
		set encodedURI to urlencode(umid) of me
		set mail_URI to "message://%3C" & encodedURI & "%3E"
		set taskTitle to theSubject
		set mail_body to content of the current_mail
		set note_content to "Original massge is: " & mail_URI & return & return & return & "Sender: " & (sender of the current_mail) & return & mail_body
	on error
		log "No message selected"
	end try
	-- Send the email straight to OmniFocus for more processing
	tell application "OmniFocus"
		tell default document
				tell quick entry
					set newTask to make new inbox task with properties {name:taskTitle, note:note_content}
					select {inbox task 1}
				end tell
			on error
				log "error"
			end try
			-- Test and see if the enty made it to Inbox, this is to prevent Mail from moving 
			-- messages that have not been filed in OF
		end tell
	end tell
	-- Move the mail to the mailbox that have been defined as the default target for actions	
	tell application "Mail"
		move current_mail to mailbox MAIL_ACTION_TARGET
	end tell
end tell
	Code snippet extracted from Waiting-For-Mails-to-OmniFocus.scpt

	Waiting For Mails to OmniFocus Script
	by, Sven Fechner

on urlencode(theText)
	set theTextEnc to ""
	repeat with eachChar in characters of theText
		set useChar to eachChar
		set eachCharNum to ASCII number of eachChar
		if eachCharNum = 32 then
			set useChar to "+"
		else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
			set firstDig to round (eachCharNum / 16) rounding down
			set secondDig to eachCharNum mod 16
			if firstDig > 9 then
				set aNum to firstDig + 55
				set firstDig to ASCII character aNum
			end if
			if secondDig > 9 then
				set aNum to secondDig + 55
				set secondDig to ASCII character aNum
			end if
			set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
			set useChar to numHex
		end if
		set theTextEnc to theTextEnc & useChar as string
	end repeat
	return theTextEnc
end urlencode