The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Need an AppleScript written (http://forums.omnigroup.com/showthread.php?t=24353)

popcornflix 2012-05-29 05:05 PM

Need an AppleScript written
 
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:

[IMG]http://i50.tinypic.com/33ou046.jpg[/IMG]

[IMG]http://i47.tinypic.com/28lrprm.jpg[/IMG]


Ends up like this:

[IMG]http://i50.tinypic.com/2wclhf4.jpg[/IMG]

Thanks in advance for helping me or for pointing me in the right direction.

RobTrew 2012-05-30 12:34 AM

[QUOTE=popcornflix;110919]It's much simpler than the other iCal to OF script listed here. Just some text manipulation.[/QUOTE]

:-)

The first rule of software consultancy is that no client proposal that includes the word [I]just[/I] 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 :-)

popcornflix 2012-05-30 06:51 AM

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.

Greg Jones 2012-05-30 08:52 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.

RobTrew 2012-05-30 11:15 AM

1 Attachment(s)
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 [URL="http://forums.omnigroup.com/attachment.php?attachmentid=2413&stc=1&d=1338404923"]here[/URL]'

(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 ...)

popcornflix 2012-05-30 03:24 PM

1 Attachment(s)
[QUOTE=RobTrew;110939]To quote Tom Lehrer, 'I have a modest example [URL="http://forums.omnigroup.com/attachment.php?attachmentid=2413&stc=1&d=1338404923"]here[/URL]'[/QUOTE]

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.[/QUOTE]

This is the line:

[CODE]set strStart to strDate & space & strFro[/CODE]

It highlighted the first semicolon.

Did I mess something up when I copied it from the XML? Text file attached.

whpalmer4 2012-05-30 03:54 PM

1 Attachment(s)
"&" needs to be "&"

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

[code]
lstContext ≠ {}
[/code]
(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 ;-)

popcornflix 2012-05-30 04:54 PM

[QUOTE=whpalmer4;110950]
I've attached a fixed but untested version.[/QUOTE]

That did it. Thanks for the assist, whpalmer4,

@RobTrew, many thanks. It works great.

Best,

.:PopCornFlix:.

RobTrew 2012-05-30 10:20 PM

Good !

Here it is [I]en clair[/I].

(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
[/CODE]

popcornflix 2014-01-10 09:51 AM

Mavericks broke script
 
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.[/QUOTE]

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[/QUOTE]

The following line in the script is highlighted:

[QUOTE]display alert ("Unexpected date: " & strStart) as string[/QUOTE]

I'd appreciate any help I can get -- this script has become a daily workhorse for me.

Thanks in advance.


All times are GMT -8. The time now is 06:57 AM.

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