I use "Launch Application/Open File..." function to attach a custom AppleScript to a shortcut keys combination. I found that the property variables within the script can't retain their values. There is no such problem when the script is launched from Script Editor or Script Debugger.
It seems that the one possible reason is that BTT recompiles a script each time a script is being called. I wonder if that's the case. If so, is there any work around?
As for the workaround, that depends on what type is the property variables, you can save it as BTT variables if it's (derived/calculated) strings or numbers; If it's reference (pointer), I cannot think of any way to hold the value.
BTT caches the scripts and usually doesn't recompile unless something changed in their code.
However I haven't found much documentation on how property variables are handled when scripts are being run through the Apple Script API. Did you find anything related? Maybe I could add some debug logs to figure out what's happening, do you have a concrete example?
I use three different methods that can retain the properties: run script by script menu, by script debugger, and by running the script from the script folder of Devonthink Pro 3.5 (DT mechanism is to compile and load a script and cache it in memory - if being placed under its own script folder).
But when attaching the same script in BTT, the properties can't be retained. So I guess the most likely reason is that BTT recompiles the script each time a script is launched.
I verify the issue easily with running this simple script (saved as applet) by using "Launch Application ..." under different launch methods:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property theVar : 10
set theVar to text returned of (display dialog "" default answer theVar)
P.S. Launch the script from automator>services won't retain the properties, too. I search the web and it seems that's also a problem with the automator.
If I use the "run script" button to test the script in BTT environment, the properties are not retained, too. Strangely, the assigned BTT shortcut won't invoke the script by this attachment method. I am not a very experience user of BTT (only for shortcuts!), so my method could be inappropriate.
You are using async background and I am using blocking. I have no idea on the difference.
Regardless, I am attaching the script applet to BTT, not saving the script in BTT config? That's why I use the "Launch application.." option.
Please correct me if I'm wrong.
Yes this was just a test to see whether it's working in general. (Background is usually better unless you need to wait for something before executing the next action)
The Run Apple Script action also allows to select a sctp file, however in that case it really recompiles. I'll fix that with the next update: