The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus 1 for Mac
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Applescript help Thread Tools Search this Thread Display Modes
I figured it out. The issue was in preferences, not the AppleScript.

-- This is the default context for newly created actions. Set to "" to not set a context.
property defaultContext : "Email"

-- If true, then rather than sending the new action directly to OF, the QuickEntry window is opened instead.
property displayQuickEntry : false

-- These four values are constants. Don't change them!
property fullContent : 0 -- Include full content of message
property summarizeContent : 1 -- Include a 3 sentence summary of the message
property firstParagraphOfContent : 2 -- Include the first paragraph of the message
property noContentInclusion : 3 -- Don't include any of the content of the message

-- The value of contentInclusionType is used to control what, if any, of the message content is included in the OmniFocus note field. Replace the text to the right of the colon with one of the four terms above to change the message content that is sent to OmniFocus.
property contentInclusionType : fullContent

-- These two properties refer to the Edit menu and the Copy command. They should be consistent across internationalization.
property editMenuNumber : 4
property copyMenuItemNumber : 5

(* Handler called when running script from script menu *)
on run
tell application "Mail"
set theSelectedMessages to selection
if ((count of theSelectedMessages) ≠ 1) then
display alert "Please select a message to be linked to the new action" message "This script creates a new OmniFocus action that links back to a selected message." buttons {"OK"} default button "OK" giving up after 20
end if
end tell
my createLinkedTask(item 1 of the theSelectedMessages, missing value)
end run

(* Handler called when running as a rule script *)
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with aMess in theMessages
my createLinkedTask(aMess)
end repeat
end tell
end perform mail action with messages
end using terms from

Creates task and link in OmniFocus for the given message.
on createLinkedTask(selected_message)
tell application "Mail"
set message_id to the message id of the selected_message
set message_subj to (subject of selected_message)
set message_sender to (extract name from sender of selected_message)
if (contentInclusionType is noContentInclusion) then
set message_content to ""
else if (contentInclusionType is summarizeContent) then
set message_content to summarize (content of selected_message as string) in 3
else if (contentInclusionType is firstParagraphOfContent) then
set message_content to (first paragraph of content of selected_message as string)
set message_content to (content of selected_message as string)
end if
end tell

tell application "OmniFocus"
set My_Task to actionPrefix & message_subj
if (includeSender) then
set My_Task to My_Task & "" & message_sender
end if
set MyDoc to first document
tell MyDoc
set theContext to ""
set propRecord to {name:My_Task}
end tell
if displayQuickEntry then
tell quick entry
set theTask to make new inbox task with properties propRecord
if (defaultContext is not "") then
set contextList to complete defaultContext as context maximum matches 1
if (contextList is not {}) then
set context of theTask to context id (id of item 1 of contextList)
end if
end if
select {inbox task 1}
end tell
if (theContext is not "") then
set propRecord to propRecord & {context:theContext}
end if
tell MyDoc
set theTask to make new inbox task with properties propRecord
if (defaultContext is not "") then
set contextList to complete defaultContext as context maximum matches 1
if (contextList is not {}) then
set context of theTask to context id (id of item 1 of contextList)
end if
end if
end tell
end if
tell theTask
set note to return & return
tell note
set theURL to "message://<" & message_id & ">"
set linkText to theURL
insert linkText at before first character
set value of attribute "link" of style of paragraph 1 to theURL
insert message_content at before last character
end tell
end tell
end tell
end createLinkedTask

Last edited by mojaverat; 2011-08-23 at 03:35 PM.. Reason: I figured it out. It was in the preferences for OF.
I don't know if this will help or not, but when I try to drag the message from "Miscellaneous" to "Inbox", it automatically moves back to "Miscellaneous".

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
XML and AppleScript seanprice OmniFocus Extras 0 2013-03-14 01:07 PM
Applescript help Shek OmniGraffle General 3 2012-09-04 04:02 AM
$$ for Applescript Help Hewdini OmniFocus Extras 1 2009-08-14 11:34 AM
Applescript Help ryan_marsh OmniFocus 1 for Mac 3 2008-11-24 08:51 AM
Help with applescript mrpuggles AppleScripting Omni Apps 1 2008-09-16 04:40 PM

All times are GMT -8. The time now is 07:15 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.