bridge from on run -> on idle

Hi all,

I want to use on run handler as initialization part of script and then, periodically (in main on idle section) use it for further operations

But AS says that my variable defined in on run section is invisible for rest of script (in on idle)

Is any way to create a “bridge” between them?


define a global or property

Hi all,

I have a routine runned in idle mode
With period of 1 min it checks if frontmost application name changed and if so, it remembers this name and do some work and and all the process repeated.

property PrevAppName: {""}
on idle
   if name of CurrApp  ≠ item 1 of PrevAppName
      set PrevAppName  to {name of CurrApp}
   end if
end idle

The problem is each time idle loop performed, value stored in first line {PrevAppName} is rewritten – however it is outside of on idle bounds.
How to fix it?

Of course it does

set PrevAppName to {name of CurrApp}

replaces the value,

set end of PrevAppName to name of CurrApp

appends it