Hi Chris,
I have an issue along these same lines.
I have a bunch of variables that are either ON or OFF / 1 or 0. The user sets them to ON or OFF via user input & checkboxes. For certain tasks the variable states are always the same, that is for Task one, VariableA = 1, VariableB = 0, for Task Two, VariableA = 1, VariableB = 1. So instead of the user having to re-check boxes when certain tasks are the same I am putting together a way to have a list of different tasks and their corresponding Variable states.
I know that I can just create a different user input prompt with the different variable states checked by default, but this is a lot of extra work if / when I ‘add’ a new variable - I have to add it to EVERY user input prompt.
More importantly, I don’t always want a user input prompt. In some cases, the Tasks are basically the same and will have the same variables, and so those Tasks will prompt the user - and the user will see the default Task Variables checked and will be able to uncheck / check what they want. But in other cases, certain tasks will always have the same variable states and so I don’t want the user to have to check anything. In these cases I need a way to set the Variable States outside of the user interaction.
The goal is to have one “Master List” of the Variables in question that I can add to in the future - so that I only have 1 place to go to change things.
Right now I have something like this:
set myVariables to {"A", "B", "C", "D", "E"}
tell application "Keyboard Maestro Engine"
repeat with i in myVariables
try
set value of variable i to 0
on error
make new variable with properties {name:i, value:0}
end try
end repeat
end tell
set defaultVariables to {"B", "C"}
if defaultVariables ≠ false then
tell application "Keyboard Maestro Engine"
repeat with i in defaultVariables
set value of variable i to 1
end repeat
end tell
end if
The main problem is that I cannot access this “myVariables” array outside of THIS AppleScript code.
I tried using the AppleScript - Save to Variable and I was able to convert the array to a list, but then I have trouble getting the list back into AppleScript so that my AppleScript code works. I’m assuming it’s because the array is converted into a list and so it would need to be converted back to an array?
set myVariables to {"A", "B", "C", "D", "E"}
set AppleScript's text item delimiters to linefeed
return myVariables as text
Save to variable: MasterVariableList
Also, is there a way to have the User Input prompt take there ‘defaults’ from the current variable value at the time that the prompt comes up? That is, if VariableA is set to 1 / ON / Checked … and then a user Prompt is shown with VariableA, can the Prompt show VariableA’s ‘current’ value?
Much appreciated!
Joe