The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Scripts which behave incorrectly when run from OF toolbar (http://forums.omnigroup.com/showthread.php?t=16450)

RobTrew 2010-06-10 11:57 PM

Scripts which behave incorrectly when run from OF toolbar
 
Some scripts behave in one way if run from the OmniFocus scripts menu, and another if run from the OmniFocus toolbar.

global variables, in particular, conserve their value between script runs if launched from the script menu, but lose their value if run from a toolbar icon.

This is a pity, as a lot of potentially useful script behaviours (various kinds of toggles, for example) are inaccessible if you want to use the toolbar.

Here is a simple example of a script which returns different results from menu and toolbar.

Try running it a few times from the menu, and then a few times from the toolbar ...

[CODE]global gtest

try
set gtest to gtest * 2
on error
set gtest to 1
end try

display dialog "This time value is " & gtest as string[/CODE]

[COLOR="White"]--[/COLOR]

RobTrew 2010-06-13 12:08 AM

[QUOTE=RobTrew;78427]Some scripts behave in one way if run from the OmniFocus scripts menu, and another if run from the OmniFocus toolbar[/QUOTE]

The reason for this discrepancy would seem to be that:[LIST=1][*]The OmniFocus script menu [B]does[/B] save a compiled script file back to disk after the script runs (normal behaviour)[*]The OmniFocus toolbar [B]omits[/B] to do this (a pity)[/LIST]
As a temporary fix, the correct behaviour can be simulated from within the code, though it is a little cumbersome.

This version should work in the same way from the OF toolbar as it does from the OF script menu ...

[CODE]set strPersist to (path to temporary items folder as string) & "Persistence.scpt"

script scrpRetainValue
property numValue : 1
end script

try
set scrpRetainValue to load script file strPersist
set numValue of scrpRetainValue to (numValue of scrpRetainValue) * 2
on error
set numValue of scrpRetainValue to 1
end try

display dialog "This time value is: " & (numValue of scrpRetainValue) as string

store script scrpRetainValue in file strPersist replacing yes
[/CODE]


All times are GMT -8. The time now is 02:57 PM.

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