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 Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Need an AppleScript written Thread Tools Search this Thread Display Modes
I need an AppleScript written for my OmniFocus workflow. It's much simpler than the other iCal to OF script listed here. Just some text manipulation.

If there's a scripting Ninja who'd like to volunteer, I'd be grateful. Otherwise, I'd be willing to pay a few bucks or buy someone beer to get it done if I have to.

I want to select a number of iCal events, and have the script convert them into individual OmniFocus actions, setting the Project, Context, Start Date and Due Date. I'd also like some other text manipulations.

Here's how I do it manually now, step by step:

(1) I select iCal events by hand, copy and paste them into OmniFocus' Quick Entry;

(2) Divide the events into separate OmniFocus Actions;

(3) Copy/Paste the Start Time to the left of the title followed by " - "

(4) Copy/Paste the date into Start Date field;

(5) Delete the word "from", then Copy/Paste the Date and Start Time into the Start Date field;

(6) Set the Project and Context (this is constant for all iCal events);

(7) Delete the iCal date information.


So what starts out looking like this:






Ends up like this:



Thanks in advance for helping me or for pointing me in the right direction.
 
Quote:
Originally Posted by popcornflix View Post
It's much simpler than the other iCal to OF script listed here. Just some text manipulation.
:-)

The first rule of software consultancy is that no client proposal that includes the word just ever turns out to be technically feasible ...

A first problem here is that the iCal Applescript library doesn't let us know which items are selected.

You can of course copy, and then work on the text contents of the clipboard, but then there's quite a lot of messy parsing to be done if you want to deal with dates, locations and other fields.

If you do find a programmer who offers to do this for a beer, or even for $100, you should accept the offer immediately :-)
 
To Applescript coders:

I didn't mean to be insulting by using the phrase "buy someone beer."

If you have the skills to write this Applescript, please contact me so we can privately discuss your fee.

Last edited by popcornflix; 2012-05-30 at 07:00 AM..
 
This probably isn't helpful either, but RobTrew is one of the most generous AppleScript coders that I have ever encountered. I use some of his scripts daily for DEVONthink, OmniFocus, and OmniOutliner and all of them were shared at no charge with the online community.

Hopefully someone will be able to assist you with what you are needing.
 
One way around iCal's reticence re the selection would be to embed the Applescript in a Keyboard Maestro macro which was restricted to iCal and prefaced the script with a Cmd-C.

To quote Tom Lehrer, 'I have a modest example here'

(This draft doesn't attempt to delete the items from iCal – best to test a bit before adding that – but Keyboard Maestro could handle that part too ...)
Attached Files
File Type: zip iCal2OF.kmlibrary.zip (3.2 KB, 2357 views)
 
Quote:
Originally Posted by RobTrew View Post
To quote Tom Lehrer, 'I have a modest example here'
Thanks, Rob. That's very generous.

I use QuicKeys instead of KM, so I opened your XML file and copied the AppleScript. When I compiled it in Apple Script Editor it threw a syntax error at line 24:

Quote:
Expected end of line, etc. but found unknown token.
This is the line:

Code:
set strStart to strDate & space & strFro
It highlighted the first semicolon.

Did I mess something up when I copied it from the XML? Text file attached.
Attached Files
File Type: txt RobTrewOmniFocus iCal Ascript.txt (3.1 KB, 1912 views)
 
"&" needs to be "&"

There are some other places that will get you errors; they need to be fixed to look like this:

Code:
lstContext ≠ {}
(for suitable values of "lstContext", of course).

I've attached a fixed but untested version.

I'd like to thank you for having the chutzpah to chide RobTrew publicly for sharing his thoughts — not everyone is so bold, and yet it seems not to have ended badly ;-)
Attached Files
File Type: applescript iCalProject.applescript (3.0 KB, 1642 views)
 
Quote:
Originally Posted by whpalmer4 View Post
I've attached a fixed but untested version.
That did it. Thanks for the assist, whpalmer4,

@RobTrew, many thanks. It works great.

Best,

.:PopCornFlix:.
 
Good !

Here it is en clair.

(I've edited it slightly to make sure that the Applescript text delimiters are properly restored at the end)

Code:
property pVer : "2.0"

property piCalProject : "iCalProject"
property piCalContext : "iCalContext"

property pDatePrefix : "\\rscheduled "
property pTimePrefix : "[0-9] from [0-9]"
property pTimeDelim : " to "
property plngPrefix : length of pDatePrefix

on run
	set strClip to (text of ((the clipboard) as record)) as string
	
	set lstActions to ParseClip(strClip)
	Add2OF(lstActions)
end run

on Add2OF(lstActions)
	tell application id "OFOC"
		tell default document
			set oProj to my GetProject(piCalProject)
			set oContext to my GetContext(piCalContext)
			
			repeat with oAct in lstActions
				set {strAction, strDate, strFrom, strTo} to oAct
				set strStart to strDate & space & strFrom
				set strDue to strDate & space & strTo
				try
					set dteStart to my date strStart
					set dteDue to my date strDue
				on error
					display alert ("Unexpected date: " & strStart) as string
					return
				end try
				tell oProj to make new task with properties {name:strAction, context:oContext, start date:dteStart, due date:dteDue}
			end repeat
		end tell
		activate
	end tell
end Add2OF

on GetProject(strName)
	tell application id "OFOC"
		tell default document
			set lstProj to flattened projects where name = strName
			if lstProj ≠ {} then
				first item of lstProj
			else
				make new project with properties {name:strName}
			end if
		end tell
	end tell
end GetProject

on GetContext(strName)
	tell application id "OFOC"
		tell default document
			set lstContext to flattened contexts where name = strName
			if lstContext ≠ {} then
				first item of lstContext
			else
				make new context with properties {name:strName}
			end if
		end tell
	end tell
end GetContext

on ParseClip(strClip)
	set {dlm, my text item delimiters} to {my text item delimiters, return & return}
	
	set lstRecs to text items of strClip
	set lstActions to {}
	repeat with oRec in lstRecs
		set lngDate to (PatternMatch(oRec, pDatePrefix)) + 1
		try
			set strAction to text 1 thru (lngDate - plngPrefix) of oRec
		on error
			return
		end try
		set strRest to text lngDate thru -1 of oRec
		set my text item delimiters to return
		set strDateTime to first text item of strRest
		set lngTime to (PatternMatch(strDateTime, pTimePrefix))
		if lngTime > 0 then
			set strDate to text 1 thru (lngTime - 7) of strDateTime
			set strTime to text lngTime thru -1 of strDateTime
			set my text item delimiters to pTimeDelim
			set {strFrom, strTo} to text items of strTime
		else
			set strDate to text 5 thru -1 of first text item of strDateTime
			set {strTime, strFrom, strTo} to {"", "", ""}
		end if
		set end of lstActions to {strAction, strDate, strFrom, strTo}
	end repeat
	set my text item delimiters to dlm
	return lstActions
end ParseClip

(* Returns position of last character of matched pattern *)
on PatternMatch(strText, strPattern)
	try
		(do shell script "echo " & quoted form of strText & " | perl -ne 'if (m/(" & strPattern & ")/) {print \"$+[1]\"}'") as integer
	on error
		0
	end try
end PatternMatch
 
Hi, I just updated to OSX Mavericks and it broke the script. Suggestions about how to fix would be appreciated.

It throws the error:

Quote:
APPLE SCRIPT ERROR: OmniFocus got an error: Can’t make string into type constant.
The result pane in AppleScript shows:

Quote:
error "OmniFocus got an error: Can’t make string into type constant." number -1700 from string to constant
The following line in the script is highlighted:

Quote:
display alert ("Unexpected date: " & strStart) as string
I'd appreciate any help I can get -- this script has become a daily workhorse for me.

Thanks in advance.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Applescript help Shek OmniGraffle General 3 2012-09-04 04:02 AM
Applescript help mojaverat OmniFocus 1 for Mac 1 2011-08-23 03:18 PM
$$ 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 08:26 AM.


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