That works, thanks.
To be honest, I didn't include any code because my attempt wasn't very close, and exposes some fundamental misunderstandings about JSL that probably come from me learning GUI scripting from AppleScript and Matlab.
I would've gotten the list of selected column names, picked the first one, but then I expected some kind of "display dialog" function which returns a string, but that apparently doesn't exist, and forces you into this new-window/list-box/button-expression syntax, which was fairly unintuitive to me, but makes more sense now that I see what it's doing. I tried ChatGPT, but it created long scripts that didn't run at all.
A few questions about your solution, if you have time:
- Why doesn't the "Cancel" button do anything? I presume because you have no 2nd argument to its Button Box() call, but what expression would close the current window? Close()? I tried "Button Box("Cancel", Close())" but it errors out with an error I don't understand. I mimicked your approach and tried "Close Window" which seems to work, but I expect there's a cleaner way to do it.
- Your "Get Selected Columns()" call has "String" as an argument, but the documentation shows that function takes no arguments. What does "String" mean here, and how did you know it would be accepted or what it does?
- I'd like to start typing immediately after running the script, but the focus isn't in the right place. I tried "teb << SetFocus;" after the "nw=..." expression, but JMP says text edit boxes don't understand that message.
- Is it possible to make Regex be case insensitive, and if so, how? (I tried adding "<IGNORECASE>" to the Regex arguments per the documentation, but it errors out.)
- Is it possible to make return/enter trigger the "Ok" script with the teb box focused?
- If the user has no selected columns, I'd like to use the first character column, but after about 20 different attempts I gave up trying to figure out which column that is.
- I would prefer the data view subset be linked, does that change the approach?
Here's what I have so far:
Names Default To Here(1);
run_expr = Expr(
dt = Current Data Table();
selCols = dt << Get Selected Columns("String");
if(N Items(selCols)==0, selCols = dt << get column names("String") );
col = selCols[1];
rgx_pattern = teb << Get Text;
dt << Select Where(!Is Missing(Regex(Column(dt, col)[Row()], rgx_pattern)));
dt << Data View; // I prefer a linked subset, what changes here?
dt << Clear Select;
wait(0);
nw << Close Window;
);
close_expr = Expr(nw << Close Window);
nw = New Window("",
H List Box(
Lineup Box(N Col(2),
Text Box("Enter regex pattern"),
teb = Text Edit Box("", <<Set Width(400))
),
Lineup Box(N Col(1),
Button Box("OK",
run_expr
),
Button Box("Cancel", close_expr)
)
)
);
teb << Set Focus();
Write();
I'd love to open Big Class, run the script, then type "ob.+t<enter>" and have it bring up a Data View of just the two Roberts. Right now it's close -- after running the script, I have to press tab, then OB.+T, then enter twice.