View Full Version : Scripting QuickEntry
curt.clifton
09-26-2007, 03:19 PM
I see some AppleScript dictionary support for QuickEntry in the latest build. Anyone figured out how to open the QuickEntry window from AppleScript yet?
Tim Wood
09-26-2007, 06:39 PM
Heh; I was just about to come post something about this.
Here are some examples:
tell app "OmniFocus"
tell quick entry
-- activate the quick entry panel for the default document
-- unlike the UI hook this won't add the default empty task
activate
end
end
tell app "OmniFocus"
tell quick entry
make new inbox task with properties {name:"foo"}
select {task 1}
save -- saves, closes and clears the panel as if you'd hit the 'Save' button
end
end
tell app "OmniFocus"
tell quick entry
close saving no -- discards the data; yes saves
end
end
tell app "OmniFocus"
tell quick entry
close -- with no 'saving' specified, just hides the panel w/o saving or reverting the data.
end
end
The 'delete' command and tree suite should be supported too (quick entry is a subclass of tree in the script suite), though I've only tested the select command so far.
All the rich text & attachment scripting should work too on task notes as well, but it's received only limited testing in the Quick Entry configuration (the code is nearly all shared, so if something is busted it should be pretty easy to fix).
I still need to support the 'complete' command and as of yet, trying to assign a context or project to an inbox item will not work if you try to mix-n-match objects from different documents (where quick entry acts like a little document of its own). You could probably work around this (untested) by finding the project/context you want in the main document and then doing something like:
tell quick entry
set context of MyTask to context id (id of MyContextFromDocument)
end
I would like to find time to auto-map these sorts of assignments, but I don't know if I'll find time before 1.0.
Tim Wood
09-26-2007, 06:44 PM
I should also mention that what I'm working on now is a clipping service with support for post-clipping script handlers to make cleanup/extensions to the clipped text based on the active application's state.
I'm out of town next week and I don't know if this will be committed before I go -- hopefully!
millieaux
10-03-2007, 09:36 AM
Anyone have any luck with this? I tried modding Curt's Mail script to open the Quick Entry and just start a new entry with title & note, but it's not working for me - even just opening the Quick Entry doesn't seem to work!
I get:
open quick entry
"OmniFocus got an error: Can't make quick entry into type file."
curt.clifton
10-03-2007, 03:23 PM
I get the same thing for open. I can get the 'make new inbox task' command to work on the QE window. Select and save also work. I opened the QE window using the hotkey, then ran this script:
tell application "OmniFocus"
tell quick entry
make new inbox task with properties {name:"foo"}
select tree 1
end tell
end tell
That part works. I'm guessing that Tim might have missed one commit before heading out so that the open command isn't implemented. I'll report via Send Feedback.
Tim Wood
10-09-2007, 09:15 PM
Bah; that's what I get for posting and then leaving for a week.
It turns out this works fine on my machine running 10.5, but not so much on 10.4 and I failed to run the test suite on 10.4 before claiming this worked.
Sorry for the false alarm -- I'll look into it.
Tim Wood
10-09-2007, 09:45 PM
OK, this should be better as of 92548. I've switched to using 'activate', which doesn't assume that its direct parameter is a file or list of files. No idea why this worked on 10.5... this is what I wanted to use in the first place, but then I got distracted and used 'open'.
I'll update the example above too for posterity.
curt.clifton
10-10-2007, 03:40 PM
Tim, we're almost there.
Here's what I almost have working now:
tell application "OmniFocus"
tell quick entry
-- Need to make task before activating or we get two tasks
make new inbox task with properties {name:"foo", note:"bar"}
activate
-- Need to use tree 1, rather than {task 1} as in
-- posted example
select tree 1
set note expanded of tree 1 to true
end tell
end tell
If I activate before making the new task, then I get two tasks: the "foo" task added by the script and a new empty task.
If I add the task before activating, then the task pane in the QE window does not have focus. That necessitates a trip to the mouse in order to edit the new task.
Also, no joy in setting the context of the QE task.
Adam Sneller
10-10-2007, 10:28 PM
Here is a script I wrote that sends a selected mail message to the Quick Entry panel. This will create a new task with a name set to the subject line of the email and the content of the message as a note. Seems to work pretty good.
The only thing I don't like is that, when Quick Entry opens, the buttons have focus. Anybody know how to shift focus to the task window?
Hope this helps!
(* New OmniFocus Action from Mail.app Message
Written by Adam Sneller
Copyright October 10, 2007. All rights reserved.
Version 1.0
*)
tell application "Mail"
-- get the currently selected message(s)
set these_messages to selection
-- if there are no messages selected, warn the user and then quit
if these_messages is {} then
display dialog "Please select a message first and then run this script." with icon 1
return
end if
-- loop through messages
repeat with this_message in these_messages
-- create link to message
set this_link to "message://" & (message id of this_message as string)
-- create task content and link to message
set this_subject to subject of this_message
set this_content to this_link & return & return & this_subject & return & date received of this_message & ¬
return & return & content of this_message
-- send task to OmniFocus
my pushToQuickEntry(this_subject, this_content)
end repeat
end tell
on pushToQuickEntry(get_name, get_note)
tell application "OmniFocus"
tell quick entry
set this_task to make new inbox task with properties {name:get_name, note:get_note}
select {this_task}
activate
end tell
end tell
end pushToQuickEntry
curt.clifton
10-11-2007, 05:15 AM
Adam, I'm not sure if you were trying to help me here, but the problem I'm having is the same one you're having. The tasks in the QE window don't have focus. (I've had the Mail side of it licked since June. See that script and my others on my software downloads page. (http://www.rose-hulman.edu/~clifton/software.html))
Adam Sneller
10-11-2007, 09:24 AM
Well, leave it to me to re-invent the wheel! From reading the forum, I got the impression that some folks were unable to get their scripts to work with Quick Entry all-together...?
But on re-reading Tim's posts (and the latest Message of the Day) it sounds like the new Clipping Services might eclipse all of this.
Has anyone gone with this approach yet?
Best,
-Adam
curt.clifton
10-11-2007, 11:29 AM
The Clipping Service only clips selected text and doesn't work with Mail Act-On. It's a partial solution, but doesn't handle quick, mouse-less inbox processing. I fully expect a solution from Omni that supersedes my own eventually. But the clipping service isn't it yet.
Tim Wood
10-11-2007, 07:39 PM
If I activate before making the new task, then I get two tasks: the "foo" task added by the script and a new empty task.
If I add the task before activating, then the task pane in the QE window does not have focus. That necessitates a trip to the mouse in order to edit the new task.
Also, no joy in setting the context of the QE task.
The implicit task creation was a typo which I've now fixed. I've also added code to the 'activate' handler on QE to make the outline be focused if it (or a subview like an editor on the note) isn't already.
For the 'select' issue you noted, I messed up my example -- 'task' won't work, but 'inbox task' will.
tell application "OmniFocus"
tell quick entry
set MyInbox to make new inbox task with properties {name:"foo", note:"bar"}
select {MyInbox}
set note expanded of first selected tree to true
activate -- Now that everything is in place, show it.
end tell
end tell
This much is fixed in 92713. I'm looking into the issue with contexts now.
Thanks for all the feedback!
Tim Wood
10-11-2007, 08:13 PM
Also, no joy in setting the context of the QE task.
I failed to test this one, it looks like. Sorry! Bad developer, no biscuit!
You should be able to access contexts in 92715.
One thing to note is that QE clones the active projects and contexts from the document when it is activated. This means that until the QE panel is on screen, the contexts and projects array will be empty. If this is a major problem, send an enhancement request =)
Here is an updated script:
tell application "OmniFocus"
tell quick entry
set MyInbox to make new inbox task with properties {name:"foo", note:"bar"}
select {MyInbox}
set note expanded of first selected tree to true
activate -- Most stuff in place; contexts aren't available until QE is on screen (they get cloned temporarily from the document at activation time)
try -- capture error if context doesn't exist
set context of MyInbox to context "Mac"
end try
end tell
end tell
Adam Sneller
10-11-2007, 09:44 PM
Tim,
I noticed that you also fixed the bug in Clipping Services with Mail.
What would really be handy is if this behaved the same way that the "Reply To" function does in Mail. If you highlight part of the message, this is what gets quoted in the reply. But, if you don't highlight anything, then the entire message is attached by default.
In this way, users could have the option to either highlight, or just enjoy an entirely mouse-free clipping!
Anyone else have an opinion on this?
-Adam
curt.clifton
10-12-2007, 07:36 AM
Thanks, Tim! I'll dig into this sometime this weekend.
Tim Wood
10-12-2007, 09:44 AM
What would really be handy is if this behaved the same way that the "Reply To" function does in Mail. If you highlight part of the message, this is what gets quoted in the reply. But, if you don't highlight anything, then the entire message is attached by default.
Yeah, that would be a nice option, but Mail doesn't support services from the message list at the top. I need to suggest to the MailTags developer that he add this in (or we could add our own .mailbundle to fix this oversight). I've logged a Radar with Apple, so hopefully they'll fix it someday, but we'll probably need to do something about it sooner than that.
Of course on the pedantic side, I'd say that most mail messages are going to have more than one issue conflated and you'll need to split it up eventually. Otherwise you're just shuffling papers around aimlessly between inboxes =) Another approach when clipping a message via the message list would be to only clip the reference to the original and a link to the sender and then let you fill out the details -- perhaps you've visually identified the action and just want to type it up rather than go select it.
Anyway, lots of UI choices, as always.
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.