Share scripts between widgets/buttons

I have several widgets using AppleScript that are similar in nature and differ only in a variable or two in the script itself. Is there a way to build a shared script that acts as a function that takes in a variable from the widget/button and then returns the result back to the calling widget/button?

You could try create the actual script in script editor, and include something like:

tell application "BetterTouchTool"
set my_variable to get_string_variable "variable_name"
end tell

then reference my_variable in the script as needed.
Then in the actual Buttons/Widgets script use:

set theScript to load script "path_to_script.scpt"
tell application "BetterTouchTool"
set_string_variable "variable_name" to "value"
end tell
run theScript

Would that work for you?

1 Like

@Doa that might work out for me. I'll give it a try when I have some time to play around with it again. I appreciate the suggestion.

Just tested the above proposed solution and it works for the case that I needed. Thanks again @Doa for proposing the solution.

1 Like

You're welcome. I'm glad it worked.