The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Selected Tasks to iCal (http://forums.omnigroup.com/showthread.php?t=5089)

uku 2007-10-06 03:35 AM

Selected Tasks to iCal
 
2 Attachment(s)
For people who don't have to sync OF tasks to any device via iCal the implemented syncing of all OF tasks to iCal seems to me pretty useless: To overcrowd iCal's todo list with all your OF tasks which are organized in a much better way in OF itself provides no benefit and creates redundancy.
On the other hand I have a couple of tasks in my OF projects which can be regarded as urgent or hard landscape tasks. These tasks I'd like to see in my hard landscape calendar. I also would like to set reminders for these tasks.

Therefore I wrote two scripts to send selected OF tasks to iCal. The first script sends one single task to a previously specified iCal calendar. The second one syncs all flagged tasks with iCal. For those who aren't afraid of nagging reminders both scripts offer the possibility to have set alarms for future todos automatically.
In both scripts OF URL linking is implemented.
(These are the first apple scripts I ever wrote, so I think the script codes aren't very smart. Perhaps someone could help me to optimize these scripts?)

uku 2007-10-06 03:46 AM

Oops! - I forgot to mention that you have to open the scripts in scripteditor to find some configuration instructions.

dhm2006 2007-10-11 11:38 AM

[QUOTE=uku;22357]Therefore I wrote two scripts to send selected OF tasks to iCal. The first script sends one single task to a previously specified iCal calendar. The second one syncs all flagged tasks with iCal.[/QUOTE]

How incredibly useful. Thank you. I never sync to iCal because there is no selection available. This works well for me.

snarke 2007-10-12 01:56 PM

Suggested alternative script
 
1 Attachment(s)
[QUOTE=uku;22357]
(These are the first apple scripts I ever wrote, so I think the script codes aren't very smart. Perhaps someone could help me to optimize these scripts?)[/QUOTE]

Clever and handy! I like them.

I've rewritten your "Task to iCal" script. It's gone from 126 lines of code to 50. :) I took out unnecessary intermediate variables, converted all the variables holding parts of the highlighted task into a record, and un-nested the redundant "if" statements in the "iCal" section.

I think a fair argument could be made that changing this
[CODE] set theNewTask to the name of theSelectedTask
set theNewNote to the note of theSelectedTask
set theNewDueDate to due date of theSelectedTask
set hasFlag to flagged of theSelectedTask
[/CODE]
into this
[CODE]set newTask to {name:name, TaskNote:note, TaskDueDate:due date, IsFlagged:flagged} of theSelectedTask
[/CODE]
isn't inherently an improvement, since it means that later on, this
[CODE]if theNewDueDate is not missing value then[/CODE]
becomes
[CODE] if TaskDueDate of newTask is not missing value then
[/CODE]
but the reason I did that was it makes it much easier to create a [I]list[/I] of new tasks, so you could highlight multiple tasks in the context window, invoke the script, and have all of them transferred to iCal at once.

I even wrote the code to collect multiple tasks. I did not rewrite the second half of my replacement script to install the multiple tasks: it will only do the first one. Why? Because I've already frittered away more than a couple hours on this, and I'm supposed to be doing other stuff. I might get back to it; you might finish the job before I do and repost it, thus saving me the effort. :)

I didn't look at your second script, but I hope you can see various tricks and techniques from this script that you could apply there as well.

benn stratton 2008-02-28 05:13 PM

I couldnt get the "improved" script to work, but the originals posted worked like a charm. A much needed capability in OmniFocus.

Thanks

snarke 2008-03-03 09:00 AM

My apologies for "improving" the script in an unfunctional way. I wonder why this bug took four months to appear. Possibilities: (1) It's very specific to Benn's situation/configuration. (2) It just appeared due to a recent change in OmniFocus. (3) Nobody else has bothered to try the revised version. (4) Lots of people have had the revised script fail, but nobody else bothered to report it. (5) Nobody else has been downloading the scripts in the first place.

I'd hate to leave a buggy script online if (2) or (4) are the case, but I don't want to invest the time if (3) or (5) are true. Sounds like Benn's satisfied with his solution of just using the original scripts, so if it's (1), I'm also off the hook. Guess I'll see if any other comments get posted.

9dragon 2008-03-06 04:05 PM

Can anybody tell me how to use these 2 scripts from uku, please? Thank you very much in advance.

braver 2008-03-12 08:26 PM

How one is supposed to invoke these scripts?

Craig 2008-03-13 05:54 AM

[QUOTE=braver;34395]How one is supposed to invoke these scripts?[/QUOTE]

[url]http://forums.omnigroup.com/showthread.php?t=7453[/url]

connie 2008-03-15 03:53 AM

script deleting calendars and returning an error message
 
Do I need to edit the script? Can't seem to get the script to work. It deletes all the names of my calendars in ical and gives me the following message:

Apple event handler failed:
make calendar with properties {name:CalendarName, writable:true, color:defaultRGB}

thanks!

Dribbler 2008-06-15 11:31 AM

I'd really like to get the flagged items script working as well- the single task script works fine, but I get the same error as connie above- anyone any idea?

mctheriot 2008-06-20 09:56 AM

I'd love to get the flagged items as well! Has anyone done this?

Mark

apeman88 2008-07-08 10:43 AM

I can't seem to find this in the iCal package:

/Applications/iCal.app/Contents/Resources/urlPrefixes.plist

I don't even get an error when trying to add a task, just the application focus shifts for a second (like I would expect) then back to OF without anything added to iCal. I am running OF version 1.02, iCal version 3.04, and OS X 10.5.4.

Another issue is that I actually had to create the Omnifocus folder in th Library/Scripts to have the folder appear in the Scripts menu in the Finder menu bar. The script also does not seem to show up when I try to change the OF menu bar as instructed in a previous thread...any thoughts?

curt.clifton 2008-07-08 11:16 AM

[QUOTE=apeman88;39568]I can't seem to find this in the iCal package:

/Applications/iCal.app/Contents/Resources/urlPrefixes.plist

I don't even get an error when trying to add a task, just the application focus shifts for a second (like I would expect) then back to OF without anything added to iCal. I am running OF version 1.02, iCal version 3.04, and OS X 10.5.4.[/QUOTE]

iCal changed quite a bit under Leopard. Was original script for Tiger?

[QUOTE=apeman88;39568]Another issue is that I actually had to create the Omnifocus folder in th Library/Scripts to have the folder appear in the Scripts menu in the Finder menu bar.[/QUOTE]

That's typical on a fresh system.

[QUOTE=apeman88;39568]The script also does not seem to show up when I try to change the OF menu bar as instructed in a previous thread...any thoughts?[/QUOTE]

Have you restarted OmniFocus since adding the Library/Scripts folder and the script?

apeman88 2008-07-08 11:22 AM

I downloaded the script from these forums, and it was posted in this thread 10-06-2007, 04:35 AM, so it may be for Tiger. Does anyone have this script working in Leopard?

Shotster 2008-07-20 11:16 AM

[QUOTE=snarke;33786]My apologies for "improving" the script in an unfunctional way.[/QUOTE]

You apparently forgot to remove/comment out the line that reads "return newTaskList" (which was presumably there for debugging purposes). I eliminated that line and it works.

-Steve

mattyork 2008-10-16 09:19 AM

Any update on this one? Just started using onminfocus for desktop and iPhone and i'd love to be able to set a default alert on iCal

Declan 2008-10-17 01:35 AM

Me too... I'd love to get these scripts to work. I have Leopard 10.5.5 here.
Thanks for making them.

snarke 2008-12-01 08:04 PM

1 Attachment(s)
[QUOTE=Shotster;41798]You apparently forgot to remove/comment out the line that reads "return newTaskList" (which was presumably there for debugging purposes). I eliminated that line and it works.

-Steve[/QUOTE]

You hit the nail on the head.

OK, OK, due to, well, not "overwhelming demand," but at least a few inquiries, and a certain amount of trying-to-avoid-other-things on my part, here is a 2.0 version of the script, with rather a lot of changes.

First of all, I fixed the aforementioned bug. {wink} Also, I have riddled it with comments. For example, somebody asked uku "Do you know if there's a way to edit this script so that the to-do does NOT contain the note and URL? I just want those fields to be left blank." It should be quite easy for anybody who wants the script to do less than it currently does to just double-click the script icon, and delete the parts that do what they don't want to have happen.

I added the second half of the code for multiple items. So, if you option-click to select multiple tasks in an OF window, then run the script, all the selected tasks will be copied to iCal.

If there are NO tasks selected when you run the script, then it will instead become the "Flagged to iCal" script, copying all flagged tasks in OF into iCal. Well, it will specifically get all tasks that are flagged, are not blocked, and are not completed.

And I've also bundled in a bonus script, called "OmniFocus Script Installer." While "tasks to iCal 2.0" has been saved as a regular script, the Script Installer is an applet. When you double click it, it will copy all script files (specifically, all files that have an extension of .scpt) that are in the same folder over to the appropriate folder for appearing in the scripting menu. (It copies the files to ~/Library/Scripts/Applications/OmniFocus, or to be very specific, to the 'OmniFocus' folder of the 'Applications' folder of the scripting folder in the user's domain, wherever that happens to be.) This little applet [I]also[/I] switches on the scripting menu in the menu bar.

If anybody finds any more bugs or problems, go ahead and post them. I'll probably get them fixed and a revised version up here in, oh, another 14 months. :eek:

snarke 2008-12-01 08:08 PM

Oh, and this was done under OS X version 10.5.5.

Also, if any other scripter wants to use "OmniFocus Script Installer," they are welcome to do so. Just give me credit for it somewhere, and perhaps tell me that you're using it.

braver 2008-12-02 11:25 AM

snarke -- cool, but it only seems to return the collected tasks; looks like it doesn't go beyond

return collectedTaskInfo

-- in Script Editor, it produces a result list, no iCal change occurs.

Also, when running the installer, no icon was added to the toolbar, had to Customize Toolbar manually... And it does nothing from there as well.

Upd.: commenting out the above return line did the trick.

OmniBrian: there's a pending Sync Flagged to iCal feature request, can you please add all posters to this thread and the download count to the votes? :)

Also -- Things do exactly this with Today instead of Flagged. However, when you un-Today in Things, the Todo immediately disappears from iCal, and toggling Today star back on makes it reappear back (try it). Yet here, unflagging a task leaves it hanging in iCal...

Checking the iCal-synced task in Things makes it complete in iCal and vice versa, here if you check a todo complete in iCal, it still shows not complete in OF.

That's why we need it as a deeply managed feature, to keep track of it by flagging/unflagging event (try that in AppleScript).

A fun way to see this is to run Anxiety with the iCal calendar you sync to, and check-uncheck, today-untoday, flag-unflag tasks in OF or Things, and see the contents of the list and stati reflect the changes at once (Things) or not (OF with tasks to iCal script).

snarke 2008-12-02 01:43 PM

1 Attachment(s)
[QUOTE=braver;51930]snarke -- cool, but it only seems to return the collected tasks; looks like it doesn't go beyond

return collectedTaskInfo

Upd.: commenting out the above return line did the trick.
[/QUOTE]

What the ****? How the [yet another expletive deleted] does that keep getting in there??

[QUOTE=braver;51930]
Also, when running the installer, no icon was added to the toolbar
[/QUOTE]

Well, that one's a mystery to me. The AppleScript command that does that is too simple to get wrong:

[CODE]
tell application "AppleScript Utility" to set Script menu enabled to true
[/CODE]

If that isn't actually enabling the script menu, I don't know what I'd change. {scratch head}

Greg Jones 2008-12-02 04:13 PM

The 2.1 version seems to be working fine for me-thanks! One question, how much trouble would it be to modify this script to also include the context in the item's title, just as it works if this option is checked in the OmniFocus>iCal sync preferences?

As example, "My Task" with a context of "Errand" located in the project "My Project" gets added to iCal as:

@Errand: My Task (My Project)

snarke 2008-12-04 11:44 AM

Version 2.2
 
1 Attachment(s)
[QUOTE]how much trouble would it be to modify this script to also include the context in the item's title?[/QUOTE]

Oh, I suppose not all that much trouble. Did you try adding it yourself? Really, AppleScript is a pretty easy language to just fiddle around in. I strongly encourage anybody using this script to at least open it up once and look around inside.

I admit it's much easier to delete or change scripts than to add things to them.
So here's version 2.2: it includes the context by default, and now has "wantContext" and "wantProject" properties, so users can easily turn those parts of the ToDo title on or off by just editing the properties at the top of the script.

[carefully checks for unwanted debugging code left behind]

[has a brainstorm]

Oh, for crying out loud. You people have got to stop making me fiddle with this script. I keep thinking of new things to add. I have [I]also[/I] added rudimentary 'completion' synchronization.

Until now, if the script found an existing ToDo item in iCal with the same name as the one it's trying to sync, it would delete the old ToDo before building the new one coming over from iCal. (This is especially important if you're syncing all flagged items.) Now, if it finds a matching existing ToDo, AND that ToDo item has been checked off, then instead of deleting/recreating it from OF, it will instead check off the task in OF as "completed."

A warning: this is done (somewhat imprecisely) by looking for a ToDo item in iCal that [I]contains[/I] the title of the OF Task. (Because the iCal ToDo title has that project and context stuff in it too). If you have a task called "Buy Groceries at Safeway" and one called "Buy Groceries", the latter might mis-match to the former and delete/replace it.

One way to avoid this would be to use the URL of the iCal ToDo item to be able to uniquely identify which OF item it originally came from. But that would involve increasing the size of the script by 50% or so, and since I'm not actually [I]using[/I] this script, I think I'll skip that function for now. Maybe when version 2.3 comes out . . . :cool:

Also, it'll only sync the 'completion' flag if you check it off in iCal, then highlight it in OF to copy it into iCal again. Or if it's flagged, and you're syncing flagged items.

But hey, it's a free bonus feature. Maybe somebody [I]else[/I] would like to improve upon it a bit? {rueful chuckle}

Greg Jones 2008-12-06 02:21 AM

Thanks snarkle, I'll take a looks at 2.2. Sorry if I sounded like I expected you to make the addition to the script. I'm not very proficient with scripting myself, but I should have worded my question "Do you know if it is possible to modify the script to..." to see if you had tried it already and found it was not possible. I do appreciate you taking the trouble to change it!

snarke 2008-12-08 04:05 PM

[QUOTE=Greg Jones;52111]Thanks snarkle, I'll take a looks at 2.2. Sorry if I sounded like I expected you to make the addition to the script.[/QUOTE]

No, no, I didn't feel like you were asking for a change. I was just trying to encourage you and anybody else reading this thread to be a little more daring, I guess. I wasn't sure if you'd already looked at the script, but hadn't been able to figure out what was going on, or if you were asking before looking.

Something else I did with the 2.2 version was added comments to almost every line of code, so that even people who've never seen the inside of an AppleScript script before should be able to figure out how it works.

After you've used it for a while, some other little tweak or addition might occur to you, and even if I'm perfectly happy to make the tweak, I might not get to it for, well, look how long it took me to do version 2.0! {rueful chuckle}

jetleets 2008-12-10 10:08 AM

Thanks snarke. Just downloaded the version 2.2 after reading this thread. Sounds like a very useful script. I will give this a try and definitely take a look at the script. Have never done any Apple scripting before, but i do write UNIX shell scripts. I do hope that they are similar in nature. I like your attitude in encouraging others to try experimenting with Apple script. Thanks again.

Well, I tried version 2.2 and it doesn't work :( Had a peek at the script but couldnt figure out what was wrong. It will most probably take me a while to figure out what the syntax for apple script. Most probably version 3.3 will be out before i am able to grasp apple script. :o

yeary 2009-01-06 05:45 PM

1 Attachment(s)
Excellent... a sync script. I just got a phone that makes this worthwhile, so I've made a few adjustments of the iCal loop to correct task creation; when I ran this script, it just checked to see if the tasks were already in iCal, then called it a day. It's attached, for your guaranty-free amusement.

darlakbrown 2009-09-07 12:05 PM

Thanks for writing and sharing this. 2.21 works ok for me. Just a little buggy with removal of tasks though, other than that working fine.

sawxray 2009-09-22 09:35 AM

Cannot get it to work...
 
Thanks so much for taking the time to create and modify this script.

It should perform a function I would love to have. Unfortunately, it does not work for me on SL.

When I activate the script in OF, the OF window loses focus for a moment. No task is created in iCal.

When I run the script in Script Editor, I get the following under Events-Replies:

[I]tell application "OmniFocus"
get document window 1 of default document
--> document window id -1 of document id "hVhsjymKO7z"
get value of selected tree of content of document window id -1 of document id "hVhsjymKO7z"
--> {task id "o0k6TcJW67m" of document id "hVhsjymKO7z"}
get name of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> "Primary Care MD: Jim Avery"
get note of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> "Jim Avery

Al Hurwitz, MD

Primary care recommendations from Edward Diao

Bill Anderick
Randy Chase

Jennifer Ross

Robert Margolin
Steven Fugaro Union St."
get due date of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> date "Tuesday, September 22, 2009 5:00:00 PM"
get flagged of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> true
get name of context of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> "Phone"
get completion date of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> missing value
get containing project of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> project id "oe1lXcRPH6f" of document id "hVhsjymKO7z"
get id of containing project of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> "oe1lXcRPH6f"
get name of containing project of task id "o0k6TcJW67m" of document id "hVhsjymKO7z"
--> "Single Actions: Personal"
end tell
tell application "iCal"
exists calendar 1 whose name = "OF:Remind"
--> true
get calendar 1 whose name = "OF:Remind"
--> calendar id "FF7EA48A-782E-4BCC-9BB5-AB1A0A3CA0DE"
exists todo 1 of calendar id "FF7EA48A-782E-4BCC-9BB5-AB1A0A3CA0DE" whose summary contains "Primary Care MD: Jim Avery"
--> false
end tell[/I]

It appears to me that the script is picking up the correct information from OF, but short circuits after finding that the To-Do does not exist in iCal.

Am I missing something?

Thanks!


All times are GMT -8. The time now is 05:02 AM.

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