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

 
Readjust Clip-O-Tron 3000 Data From Mail.App Thread Tools Search this Thread Display Modes
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.
 
+1 I need this too...I just need a link back to the original.
 
If you just select some text in the message and invoke the clipping shortcut, you'll get:


(I had selected just the subject line)

which is just a triple-click plus the clipping shortcut to execute.
 
Quote:
Originally Posted by Newtdude View Post
I'm trying to readjust the Clip-O-Tron 3000 ... I found the AppleScript for Mail-Leopard at:

...and so on...
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.
 
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 (http://www.red-sweater.com/fastscripts/) 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. Please note I have some questions towards the end of this post for Omni and/or the community.

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
Okay so my questions, some of which may need to be answered by Omni...
  1. Why does tell applicatation 'OmniFocus' / activate quick entry / end tell 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?
  2. 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.
  3. 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.
 
Happy to help! Checked with a coworker, who had these suggestions.

Quote:
Originally Posted by Newtdude View Post
Why does tell applicatation 'OmniFocus' / activate quick entry / end tell 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?
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

Quote:
Originally Posted by Newtdude View Post
Is there a less hacky way to expand the notes of each of the tasks in the Quick Entry window?
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
Quote:
Originally Posted by Newtdude View Post
Is there any better way to manipulate the task items in the quick entry?
Try this:

Code:
tell application "OmniFocus"
	tell quick entry
		select first tree
	end tell
end tell
Do those help?

Last edited by Brian; 2011-02-25 at 03:26 PM.. Reason: reformat whitespace, add parenthetical.
 
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
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sandboxing and Clip-o-Tron 3000 cashdollar OmniFocus 1 for Mac 1 2012-06-08 12:41 PM
Mail Clip-O-Tron 3000 kanders001 OmniFocus 1 for Mac 1 2009-11-12 02:42 PM
Clip-O-Tron 3000 - Mail Clipping does not work?? nima2008 OmniFocus Extras 2 2008-09-19 05:36 AM
Clip-O-Tron 3000... frankmcma OmniFocus 1 for Mac 5 2008-08-01 07:16 AM
Mail Clip-O-Tron 3000 has me baffled? jwhitetoo OmniFocus 1 for Mac 5 2008-01-14 10:35 AM


All times are GMT -8. The time now is 09:52 AM.


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