The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Default window doesn't open after running Applescript (http://forums.omnigroup.com/showthread.php?t=18745)

ryans 2010-10-29 12:45 PM

Default window doesn't open after running Applescript
 
I'm having an issue with OmniFocus's behavior after running an Applescript. Here's what happens to me on multiple machines:

1) Open an Omnifocus window. Close it with Command-W or the red button. Note that clicking on the dock icon brings your Omnifocus window back to the foreground.

2) Execute the following Applescript with the Omnifocus window closed. This is the simplest Applescript that I can reproduce the problem with:

[CODE]tell application "OmniFocus"
tell the default document to tell the front document window
set perspective name to "Inbox"
end tell
end tell[/CODE]

3) Click on the Omnifocus icon in the dock. The document no longer opens and I need to open a new window with File->New Window or Command-Option-N to use the app again. Quitting the application and relaunching fixes the behavior until the script is run again.

Am I doing something wrong in my Applescript, or is this a bug in Omnifocus? Is there any sort of workaround? I want to be able to use this to periodically export data, so running it with the window open isn't always possible.

Brian 2010-10-29 01:56 PM

I'm not positive that's a bug, but I can reproduce the behavior and it's certainly not helpful, so I'm going to write it up that way. :-)

Suggested workaround in the meantime would be to make a new window with the "visible" property set to False, do the export, then close the hidden window. Does that help?

I'll give this a stab, but I have more experience scripting OmniOutliner or OmniGraffle, so just in case you beat me to it, I thought I'd post the suggestion before I had a script together...

Brian 2010-10-29 02:26 PM

Hmmm... okay, I'm able to work around the bug in the following while visible is set to true, but once I run the script with that set back to false, I get the same 'no window' response to a click on the dock icon.

[CODE]
tell application "OmniFocus"
tell the default document
set theWindow to make new document window with properties {visible:false, perspective name:"Inbox"}
close theWindow
end tell
end tell
[/CODE]


It may be that the best option is a script that opens the window, does the export, then closes the window for the time being. Apologies!

(Attaching this info to the bug I filed, as well.)

ryans 2010-10-29 02:55 PM

[QUOTE=Brian;88252]Hmmm... okay, I'm able to work around the bug in the following while visible is set to true, but once I run the script with that set back to false, I get the same 'no window' response to a click on the dock icon.
)[/QUOTE]

Thanks for your help. I can reproduce it with visible set either way. Setting visible to true pops up the window, the export is completed, then the dock icon no longer works. Interestingly, the export doesn't appear to be happening if visible is set to false.

[CODE]

tell application "OmniFocus"
tell default document
set theWindow to make new document window with properties {visible:true}
tell theWindow
set perspective name to "Home"
save in "Users:username:Dropbox:HomeContextExportForMobile" as "HTML"
close
end tell
end tell
end tell
[/CODE]

RobTrew 2010-10-29 09:48 PM

[QUOTE=ryans;88259]Interestingly, the export doesn't appear to be happening if visible is set to false.[/QUOTE]

When a window is made invisible, the Applescript interface to it is destroyed and has to be recreated. This is a bug which I reported [OG #556132] when writing my [URL="http://bit.ly/OF-Find2"]Where in OF[/URL] script, which resorts to workarounds at more than one point. (Likewise the '[URL="http://forums.omnigroup.com/showthread.php?t=17894"]Home Page[/URL]' toolbar button)

I think Tim indicated that he had some insight into why this might occur. My guess is that it is relevant to the problems described in this thread.

A simple illustration:
[CODE]tell application id "com.omnigroup.omnifocus"
tell default document
set oWin to make new document window
display dialog (id of oWin) as string with title "id of new Window"

set visible of oWin to false
display dialog (id of oWin) as string with title "id of new Window once invisible" -- fails.

end tell
end tell[/CODE]


All times are GMT -8. The time now is 05:09 PM.

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