PDA

View Full Version : Reveal Script (switch alternative)


Alex Brown
2007-11-06, 06:00 AM
Here's a script which provides a useful alternative to the switch operation, aka show in (context|planning) mode, or twin

When applied to a single leaf action (not in the inbox), it opens a new window focussed on the project that contains the action, with filters in a default state, allowing you to see the other actions remaining on that project.

This allows you to quickly see if next actions exist, and create or adjust them as necessary before completing your actions and closing the new window.

You can then continue working in the original window where you left off.

I use this a lot.

To install, copy Reveal.scpt from the zip file to ~/Library/Scripts/Applications/Omnifocus and restart Omnifocus. You can add it to your Omnifocus toolbar by right clicking on the toolbar and selecting "Customize Toolbar".

UPDATED 30/12/07 - 1.4.2 use this if 1.4.3 doesn't work for you. [deleted]
UPDATED 30/12/07 - 1.4.3 recommended version (works like original 1.4.0 version). [deleted]
UPDATED 4/12/07 - 1.4.4 fix for "not an action" due to inbox task rename to task in scripting interface
UPDATED 10/5/07 - 2.0.5ß cleanup - might fix the pi issue mentioned elsewhere. Known bug: additional 'main' script visible in Customise Toolbar

ßeta users note: you should delete any existing Reveal scripts from ~/Library/Scripts/Applications/Omnifocus before installing the new Reveal Script.

The script "Pan Out" is also available elsewhere on this site; it expands the focus to include the parents of the current focus.

-Alex Brown

Craig
2007-11-06, 09:50 AM
Hey, thanks Alex! This is just about what I was wishing for months ago (http://forums.omnigroup.com/showpost.php?p=18043&postcount=1)!

dbyler
2007-11-12, 10:19 AM
Agree: this is a useful little tool. Thanks also for making an icon for it; there's nothing worse than a generic script icon in the toolbar.

steve
2007-11-18, 07:00 AM
This is so useful it seems like it should be baked in. Thanks for making it!

uku
2007-11-22, 05:00 AM
Thank you, Alex, for this awfully usefull script! It became part of my workflow when completing actions in context mode.

Unfortunately it doesn't work anymore since I installed the latest updates (currently r 94950). When I start the script I get the error message:

AppleScript reported the following error:
The variable w is not defined.

I looked at the script to edit it but I'm not shure how to re-define this variable |w|.

So, can you help me to get the script work again?

Craig
2007-11-22, 07:15 AM
Thank you, Alex, for this awfully usefull script! It became part of my workflow when completing actions in context mode.

Unfortunately it doesn't work anymore since I installed the latest updates (currently r 94950). When I start the script I get the error message:

AppleScript reported the following error:
The variable w is not defined.

Just a me-too post, on the gratefulness and on the error report.

curt.clifton
2007-11-22, 07:20 AM
A recent OF build changed window access. Here's a fix.

Change the line:

set |w| to (first document window whose index is 1)


To:

set |w| to document window 1

uku
2007-11-22, 07:47 AM
A recent OF build changed window access. Here's a fix.



Thank you, Curt! The script runs again!

By the way, is there any documentation of the OF script suite?

curt.clifton
2007-11-22, 08:10 AM
By the way, is there any documentation of the OF script suite?

Just the usual Applescript dictionary, available from File --> Open Dictionary in Script Editor. There are lots of open-source scripts floating around also. My collection is available here (http://www.rose-hulman.edu/~clifton/software.html). (I'll be revving a bunch of those soon, as many of my scripts suffered from the same problem as Alex's Reveal script.)

jasong
2007-11-25, 12:44 AM
Any suggestions on handling multiple open windows? As written (with Curt's fix) the script takes the selection from the first window, which may not be the frontmost window.

curt.clifton
2007-11-25, 07:22 AM
I think this is actually an OF bug. Typically "document window 1" or "front document window" would get the frontmost window. It doesn't in OF. The original code in the reveal script used to work around this bug, but doesn't seem to anymore.

(Sent as feedback.)

Craig
2007-11-26, 02:36 PM
Is anyone else getting a "you have not selected an action" error though you have?

steve
2007-11-27, 09:13 AM
Darn! This had become a applescript that I used throughout the day.

I'm getting this message:

AppleScript reported the following error:
OmniFocus got an error: Unable to locate the object to select.

Again, Omni, please hardwire this applescript.

spnyc
2007-11-27, 09:33 AM
thanks for putting this together. that being said, i haven't been able to get it to work; i'm getting an applescript error even after applying curt's patch from above:

AppleScript reported the following error:
OmniFocus got an error: Unable to locate the object to select.

looks like it's having issues selecting the containing project of the selectedItem

Build: 95177

Alex Brown
2007-11-30, 08:06 AM
Hi All,

Sorry for the silence, I haven't looked at the board for a week or two.

I'm still using reveal 1.4 (the one I uploaded) today, on revision 95390 of OF, and I'm not seeing any of the problems listed above.

Are people still having problems with Reveal? If you can provide detailed instructions that can replicate the problem in my OF, then I will provide a fix.

-Alex

Craig
2007-11-30, 08:22 AM
I just now updated my OF and it looks like the script is working again.

Alex Brown
2007-11-30, 08:50 AM
I've uploaded a new version with curt clifton's fix, which is think should fix both of the error messages above. That is version 1.4.2. It has problems if you have multiple windows open.

Version 1.4.3 is exactly like the original version that some people reported problems with for a few revisions of omnifocus. If it works for you (it works for me), it will get actions from the frontmost window.

Alex Brown
2007-11-30, 09:16 AM
Note that OF have provided 1/2 of the functionality of reveal now, as noted in their release notes:

* Hooked up double-click on projects & tasks in the content area so that you'll get a new window focused on the project. Fixed up the window creation to not show the window in an unfocused state and to select the focused projects.

This still has some problems in that it inherits the view mode and filters from the most recently closed window, which is a bit random. I have high hopes, however.

steve
2007-12-07, 05:59 AM
Today in revision 95742, the reveal script stopped working. I get the message: "you have selected something that isn't an action."

Does anyone else get this?

"Show in Planning mode" works, but I like how the reveal script opens the planning view in a new window.

Alex Brown
2007-12-07, 06:46 AM
have you downloaded the current reveal version 1.4.4 from the top post in this thread? Omnifocus recently fixed a longstanding mistake in the scripting interface which identified all actions as inbox tasks, and since the reveal script used the old terminology, it broke. 1.4.4 should fix that; if not, let me know.

steve
2007-12-07, 01:58 PM
It is fixed. Thanks!
Love it— this is an essential script.

umop
2008-03-05, 01:28 PM
At this line:


set t to leaf id pi -- this errors if focus is on, (OF bug?)


I get the error:

Can't get leaf id "____" of library of sidebar of document
window id -1 of document id "_____".


Anyone else? Any thoughts?

Thanks,
Eric

RobTrew
2008-03-06, 04:47 AM
The problem seems to be that Alex is trying to use "pi" as a variable name.

set pi to id of P
set t to leaf id pi -- this errors if focus is on, (OF bug?)

As it happens "pi" is an Applescript constant with a value a little over 3.14 ...

umop
2008-03-06, 09:33 AM
even with

set pident to id of P
set t to leaf id pident -- this errors if focus is on, (OF bug?)

it still has the same problem (plus, I'd expect a lot more people than me to have the problem if the PI const was the issue). Good point / catch, though.

umop
2008-03-06, 09:34 AM
I wonder what "if focus is on" means

RobTrew
2008-03-06, 12:34 PM
Something less sophisticated that may serve as a stop-gap in the meanwhile. In addition to tasks in project and context views, should also work for inbox tasks that have an assigned project.

tell application "OmniFocus"
tell window 1
try
set lstTrees to selected trees of content
on error
return
end try
if (count of lstTrees) > 0 then
set oValue to value of item 1 of lstTrees
if class of oValue = task then
set idTask to id of oValue
set oProj to containing project of oValue
tell front document of application "OmniFocus"
set winFocus to make new document window with properties ¬
{selected view mode identifier:"project", search term:""}
end tell
tell winFocus
set focus to {oProj}
my Expand(item 1 of trees of content)
tell content
select leaf id idTask
end tell
end tell
else if class of oValue = inbox task then
set idTask to id of oValue
set oProj to assigned container of oValue
if class of oProj = project then
tell front document of application "OmniFocus"
set winFocus to make new document window with properties ¬
{selected view mode identifier:"project", search term:"", focus:{oProj}}
end tell
tell winFocus
tell sidebar
select every leaf
end tell
tell content
select leaf id idTask
end tell
my Expand(last item of trees of content)
end tell
end if
end if
end if
end tell
end tell


on Expand(oTree)
using terms from application "OmniFocus"
set oSubTrees to trees of oTree

if (count of oSubTrees) > 0 then
set expanded of oTree to true
repeat with oSubTree in oSubTrees
Expand(oSubTree, true)
end repeat
end if
end using terms from
end Expand

librarymonkey27
2008-03-06, 01:33 PM
Just the usual Applescript dictionary, available from File --> Open Dictionary in Script Editor. There are lots of open-source scripts floating around also. My collection is available here (http://www.rose-hulman.edu/%7Eclifton/software.html). (I'll be revving a bunch of those soon, as many of my scripts suffered from the same problem as Alex's Reveal script.)

anther way to get the dictionary is to have script editor open or the icon in sight and drag your application into it ===

Script editor will open up the dictionary for that program (and the standard dictionary)

Alex Brown
2008-03-10, 07:51 AM
Please try version 2.05ß which I have uploaded. This version is greatly cleaned up from previous versions, and doesn't even contain the code you mention!

Let me know how you get on.

Craig
2008-03-10, 08:55 AM
I'm getting "You have selected something that isn't an action" with the beta, when launched from the toolbar.

edit: Two "Reveal" scripts are listed in my scripts menu - the first yields the same error, the second works.

edit 2: If I put the "Main" script in my toolbar and launch it, that works.

Alex Brown
2008-03-10, 09:22 AM
Hi Craig,

Firstly, yeah, sorry, this is a beta, I can explain, and there's something I'd like you to try.

In order to 'fix' some horribleness with losing icons and version control, I am now using a script bundle. Script bundles are not perfectly supported by Omnifocus.

Since script bundles have a different extension (scptd) to simple compiled scripts (scpt), This means the new version you have installed does not replace the old version 1 reveal script. Please look in ~/Library/Scripts/Applications/Omnifocus. You should see 2 scripts called Reveal. You can use Show Info to see their full filenames - Reveal.scpt and Reveal.scptd.

For the moment, please rename Reveal.scpt to Reveal1.scpt.

When you restart omnifocus you should see 3 scripts in the customise toolbar view: Reveal1, Reveal and main.

I expect that Reveal (the new one) and main (the works inside the new one) will operate correctly, and the same as each other. Please let me know if that doesn't work. If it does work, please delete (or backup and delete) Reveal1.scpt and just ignore the script 'main'.

Thanks for trying out my beta software!

Alex Brown
2008-03-10, 09:28 AM
If any knows how to combine a script (scpt) and an icon (icns) to create a script with an icon (without using the GUI) please let me know.

I'm using git to version control code changes to reveal. Each time I revert, the resource fork containing the icon is deleted. Resource forks are a pain anyway, I'm better without them.

I have resorted to having a pre-iconned scptd script bundle into which I osacompile the applescript. However, OmniFocus doesn't perfectly support script bundles - you can see the main.scpt inside them from the customise toolbar sheet.

What I really want to do is have a command line do the meaning of the following:

osacompile -d -o Reveal.scpt Reveal\ Dev.applescript
osascript <(echo tell Finder to set icon of file "Reveal.scpt" to Reveal.icns)

Yeah I know that's not valid script - but there doesn't appear to BE a valid script to do that.

<i>Update: I know how to do this now (see post later in this thread)</i>

Craig
2008-03-10, 09:41 AM
For the moment, please rename Reveal.scpt to Reveal1.scpt.

When you restart omnifocus you should see 3 scripts in the customise toolbar view: Reveal1, Reveal and main.

I expect that Reveal (the new one) and main (the works inside the new one) will operate correctly, and the same as each other. Please let me know if that doesn't work. If it does work, please delete (or backup and delete) Reveal1.scpt and just ignore the script 'main'.

I just deleted both reveals, redownloaded and reinstalled the beta, and it's working. Thanks!

Alex Brown
2008-03-11, 11:43 AM
To add icons to your script: (makefile format)

inputs: Reveal\ Dev.applescript - text sourcefile
inputs: Reveal.icns - icon with picture in 32x32 icon. (Icon Composer).
====
Reveal.scpt: Reveal\ Dev.applescript Reveal.r
osacompile -d -o "$@" "$<"
setFile -a "E" "$@" # Hide extension
setFile -a "C" "$@" # allow custom icon
Rez Reveal.r -o "$@" # set custom icon using resource script

Reveal.r: Reveal.icns
echo 'read '\''icns'\'' (-16455) "$<";' > "$@"
====

RobTrew
2008-03-11, 12:05 PM
To add icons to your script: (makefile format)

inputs: Reveal\ Dev.applescript - text sourcefile
inputs: Reveal.icns - icon with picture in 32x32 icon. (Icon Composer).
====
Reveal.scpt: Reveal\ Dev.applescript Reveal.r
osacompile -d -o "$@" "$<"
setFile -a "E" "$@" # Hide extension
setFile -a "C" "$@" # allow custom icon
Rez Reveal.r -o "$@" # set custom icon using resource script

Reveal.r: Reveal.icns
echo 'read '\''icns'\'' (-16455) "$<";' > "$@"
====

Or, for simplicity, if you do want to use the GUI, just:

Select the script in the Finder
Use Apple-I to open the Info dialog
Select the icon at the top-left of the dialog
Paste any graphic (of any size)

Alex Brown
2008-03-12, 03:28 AM
Thanks, I'd been doing that but it's a pain if I have to do that every time the resource fork gets blown. Easier to have a script.

RobTrew
2008-03-12, 03:58 AM
Thanks, I'd been doing that but it's a pain if I have to do that every time the resource fork gets blown. Easier to have a script.

Yes - we tend to oversell the "ease" of the GUI (and the "difficulty" of the command lines and code).