Navigate to a particular frame of a stack with ImageJ macro

I have written a macro to open a tiff time-series, allow me to manually select some ROIs of interest and measure brightness over time.
When the stack is open I am using the ‘auto’ brightness & contrast tool for easier viewing and ROI selection (I reset this before taking the measurements). I would like to use the ‘auto’ tool on the final image in the time-series, since this the palest. However I can’t find a way to navigate through the stack with the macro tool (when I use the macro recorder, nothing appears in the window when I manually navigate through the stack). Is there a way to ask the macro to go to a particular image in a stack before applying the brightness/contrast correction?
Thanks for the help.

You need to use the setSlice(n) function:

For macro programming you can always search for the in built functions in case the recorder is not giving you what you need:

Thank you for the help.