The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus 1 for Mac (http://forums.omnigroup.com/forumdisplay.php?f=38)
-   -   Readjust Clip-O-Tron 3000 Data From Mail.App (http://forums.omnigroup.com/showthread.php?t=20147)

Newtdude 2011-02-15 02:12 AM

Readjust Clip-O-Tron 3000 Data From Mail.App
 
I have a quick question I'm hoping someone might have an answer to. I'm trying to readjust the Clip-O-Tron 3000 so that when I activate it from Mail.app, I just get the link to the mail message selected. Out of the box it creates a "From: " value, the message link, and pastes in a the body of the selected message. I found the AppleScript for Mail-Leopard at:

/OmniFocus/OmniFocus.app/Contents/PlugIns/BuiltInClippingHandlers.plugin/Contents/Resources/

...but from what I can tell this just deals with the "From: " value and the message link. Regardless of what is in this script, I still get the body of the mail message.

Does anyone know if or how OmniFocus can be adjusted to avoid getting the message body? Is there a plist value I can change or another AppleScript somewhere I need to hack on? Thanks in advance.

figman 2011-02-15 11:13 AM

+1 I need this too...I just need a link back to the original.

whpalmer4 2011-02-15 11:26 AM

If you just select some text in the message and invoke the clipping shortcut, you'll get:
[URL=http://img222.imageshack.us/i/screenshot20110215at122.png/][IMG]http://img222.imageshack.us/img222/4826/screenshot20110215at122.png[/IMG][/URL]

(I had selected just the subject line)

which is just a triple-click plus the clipping shortcut to execute.

rh26 2011-02-15 08:48 PM

[QUOTE=Newtdude;93353]I'm trying to readjust the Clip-O-Tron 3000 ... I found the AppleScript for Mail-Leopard at:

...and so on...[/QUOTE]
Doesn't this make you wish there was some UI in preferences to control the Clip-O-Tron? Like checkboxes for Link, From, Subject, Body, etc.

IMO, Clip-O-Tron functionality needs to be more tightly integrated into OF. Requiring me to be an Applescript programmer can't be the right answer.

Newtdude 2011-02-24 10:21 PM

Thanks everyone for your comments and suggestions. There was no solution that exactly fit my needs so I created my own AppleScript to perform the functionality. In my own case I'm using FastScript ([URL="http://www.red-sweater.com/fastscripts/"]http://www.red-sweater.com/fastscripts/[/URL]) for a hotkey in Mail. This script works on a single or multiple messages and although this does exactly what I need it to, your own mileage may vary. [B]Please note I have some questions towards the end of this post for Omni and/or the community.[/B]

[CODE]-- FROM /OmniFocus.app/Contents/PlugIns/BuiltInClippingHandlers.plugin/Contents/Resources/Mail-Leopard.applescript
-- Trims "foo <foo@bar.com>" down to "foo@bar.com"
on trim_address(theAddress)
try
set AppleScript's text item delimiters to "<"
set WithoutPrefix to item 2 of theAddress's text items
set AppleScript's text item delimiters to ">"
set MyResult to item 1 of WithoutPrefix's text items
on error
set MyResult to theAddress
end try
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
return MyResult
end trim_address

-- BASE SCRIPT FROM http://forums.omnigroup.com/showthread.php?t=6182
set messageCount to 0
tell application "Mail"
-- get the currently selected message or messages
set selectedMessages to selection

-- if there are no messages selected, do nothing
if selectedMessages is not {} then
set messageCount to count of selectedMessages
repeat with i from 1 to messageCount
-- parse the email(s)
set theMessage to item (i) of selectedMessages
set theName to subject of theMessage
set theMessageID to (content of header "Message-Id") of theMessage
set theMessageID to my trim_address(theMessageID)
set theMessageURL to ("message:<" & theMessageID & ">")

-- create new task in quick entry
tell application "OmniFocus"
activate
set theTask to theName
set theNote to "Original Message"
tell quick entry
set NewTask to make new inbox task with properties {name:theTask, note:theNote}
set value of attribute "link" of style of note of NewTask to theMessageURL
end tell
end tell
end repeat
end if
end tell

-- Method 1: Use native AppleScript
-- THIS IS SUPPOSSED TO WORK, BUT FAILS
-- tell applicatation "OmniFocus"
-- activate quick entry
-- end tell

-- Method 2: Use your native hotkey
-- You will need to adjust the keystroke to
-- what you have defined in your OF prefs
--tell application "System Events"
-- keystroke space using {control down, option down}
--end tell

-- Method 3: Use the menu via AppleScript GUI Scripting
-- You must have "Enable access for assistive devices"
-- turned on in System Preferences Universal Access
tell application "System Events"
tell process "OmniFocus"
tell menu bar 1
tell menu bar item "Window"
tell menu "Window"
click menu item "Show Quick Entry"
end tell
end tell
end tell
end tell
end tell

-- SELECT TASK & EXPAND NOTES FOR FINAL MANUAL EDITING
-- Note: Just change the expandNote value to false
-- if you don't care to have the task notes expanded

set expandNote to true
tell application "System Events"
keystroke tab
keystroke (key code 53) -- Escape

-- Note expansion code
if expandNote is true then
keystroke "'" using {command down}
keystroke (key code 53) -- Escape
if messageCount > 1 then
-- Expand all note items
repeat with i from 2 to messageCount
keystroke (key code 125) -- Arrow Down
keystroke "'" using {command down}
keystroke (key code 53) -- Escape
end repeat
-- Cursor up first item
repeat with i from 1 to messageCount
keystroke (key code 126) -- Arrow Up
end repeat
end if
end if

-- Select first task text for manual editing if needed
keystroke tab
end tell[/CODE]

Okay so my questions, some of which may need to be answered by Omni...
[LIST=1][*]Why does [I]tell applicatation 'OmniFocus' / activate quick entry / end tell[/I] fail? Essentially this does nothing even though there is some indication within the community that this works although other folks state it doesn't but should. Is this by chance a bug?[*]Is there a less hacky way to expand the notes of each of the tasks in the Quick Entry window? I spent a bit of time trying to get/set "note expanded" but it never quite worked even though I could definitely get/set the boolean.[*]Is there any better way to manipulate the task items in the quick entry? For example you see a bunch of AppleScript GUI code to select the task text of the first task in the quick entry list. I'm hoping there's a cleaner way of doing this.[/LIST]

Brian 2011-02-25 02:23 PM

Happy to help! Checked with a coworker, who had these suggestions.

[QUOTE=Newtdude;94122]Why does [I]tell applicatation 'OmniFocus' / activate quick entry / end tell[/I] fail? Essentially this does nothing even though there is some indication within the community that this works although other folks state it doesn't but should. Is this by chance a bug?
[/QUOTE]

There are 2 things going on here - you want to use "open" instead of "activate" and it turns out that Cocoa scripting isn't initialized until you need it, and "open" for some reason doesn't do so.

If you add a "get class" line to a script, though, that forces Cocoa Scripting to initialize, and the open command will then work as expected. (We filed a request to just automatically initialize scripting when the app launches, but until that makes it into the app, you'll want to use this workaround.)

[CODE]
tell application "OmniFocus"
(get class of quick entry) -- Force Cocoa Scripting to initialize
open quick entry
end tell
[/CODE]


[QUOTE=Newtdude;94122]Is there a less hacky way to expand the notes of each of the tasks in the Quick Entry window?[/QUOTE]

This should work:

[CODE]tell application "OmniFocus"
tell quick entry
repeat with t in every tree
set note expanded of t to true
end repeat
end tell
end tell[/CODE]

[QUOTE=Newtdude;94122]Is there any better way to manipulate the task items in the quick entry?
[/QUOTE]

Try this:

[CODE]tell application "OmniFocus"
tell quick entry
select first tree
end tell
end tell[/CODE]

Do those help?

Newtdude 2011-02-28 10:08 AM

Brian, many thanks and these new script snippets work great! For those following along or who may stumble across this thread down the road, here's the final streamlined script:

[CODE]-- FROM /OmniFocus.app/Contents/PlugIns/BuiltInClippingHandlers.plugin/Contents/Resources/Mail-Leopard.applescript
-- Trims "foo <foo@bar.com>" down to "foo@bar.com"
on trim_address(theAddress)
try
set AppleScript's text item delimiters to "<"
set WithoutPrefix to item 2 of theAddress's text items
set AppleScript's text item delimiters to ">"
set MyResult to item 1 of WithoutPrefix's text items
on error
set MyResult to theAddress
end try
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
return MyResult
end trim_address

-- BASE SCRIPT FROM http://forums.omnigroup.com/showthread.php?t=6182
set messageCount to 0
tell application "Mail"
-- GET THE CURRENTLY SELECTED MESSAGE OR MESSAGES
set selectedMessages to selection

-- IF THERE ARE NO MESSAGES SELECTED, DO NOTHING
if selectedMessages is not {} then
set messageCount to count of selectedMessages
repeat with i from 1 to messageCount
-- parse the email(s)
set theMessage to item (i) of selectedMessages
set theName to subject of theMessage
set theMessageID to (content of header "Message-Id") of theMessage
set theMessageID to my trim_address(theMessageID)
set theMessageURL to ("message:<" & theMessageID & ">")

-- CREATE NEW TASK IN QUICK ENTRY
tell application "OmniFocus"
activate
set theTask to theName
set theNote to "Original Message"
tell quick entry
set NewTask to make new inbox task with properties {name:theTask, note:theNote}
set value of attribute "link" of style of note of NewTask to theMessageURL
end tell
end tell
end repeat
end if
end tell

-- SELECT TASK & EXPAND NOTES FOR FINAL MANUAL EDITING
tell application "OmniFocus"
-- OPEN QUICK ENTRY DIALOG
(get class of quick entry) -- Added to initialize Coca Scripting
open quick entry
tell quick entry
repeat with i in every tree
set note expanded of i to true
end repeat
-- SELECT TASK TEXT FOR MANUAL EDITING IF REQUIRED
select first tree
tell application "System Events"
keystroke tab
end tell
end tell
end tell[/CODE]


All times are GMT -8. The time now is 01:49 PM.

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