View Single Post
I had some fun playing with this tonight and made a few enhancements. My updated version is below. Significant changes:
  • got rid of the alert dialog that would appear if no items were selected,
  • added bullets in front of the items,
  • added a property to set the maximum length of displayed actions. Any actions longer than this are truncated now. Set it really large to avoid truncation.

Install instructions above still apply, but here's the updated code:
Code:
(*
	This script works with GeekTool to display the currently selected actions in OmniFocus. This script is modified from a script originally designed to display the currently selected actions in Growl.
	
	version 0.2, by James A. Jones
	version 0.1, by Curt Clifton

	Copyright  2009, James A. Jones
	Copyright  2007-2009, Curtis Clifton
	
	All rights reserved.
	
	Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
	
		 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
		
		 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
		
	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
	
	version 0.2.1: Eliminated alert dialog for no actions selected, misc. enhancements
	version 0.2: GeekTool modification
	version 0.1: Original release
*)

-- Edit the number in the line below to control maximum number of characters for each displayed action:
property maximumLength : 25

property actionBullet : "* "
property noSelectionMessage : "[no actions selected in OmniFocus]"

tell application "OmniFocus"
	tell front document
		tell content of document window 1
			set theSelectedItems to name of every selected tree
			if ((count of theSelectedItems) < 1) then
				return noSelectionMessage
			end if
		end tell
	end tell
end tell

set theSelectedItems to my trimItems(theSelectedItems, {})

-- Standard Applescript incantation to turn a list into a delimited string:
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to (return & actionBullet)
set theItemsText to theSelectedItems as text
set AppleScript's text item delimiters to oldDelim
-- Slaps a bullet on the front and returns the string:
return actionBullet & theItemsText

on trimItems(xs, accum)
	if xs is {} then return reverse of accum
	set truncatedItem to item 1 of xs
	if ((length of truncatedItem) > maximumLength) then
		set truncatedItem to text from character 1 to character maximumLength of truncatedItem
		set truncatedItem to truncatedItem & "..."
	end if
	set accum to {truncatedItem} & accum
	return trimItems(rest of xs, accum)
end trimItems
__________________
Cheers,

Curt