How to scan the wireless interface and save it to a file

I am wanting to create a simple script that scans the wireless interface to get SSID’s and DBM level of surrounding wireless devices.

Here is what I have so far:

:local wirelessList "";

:set wirelessList [/interface wireless scan wlan1 duration=7s];

:log info "Saving scan to file"

/file print file=scan
/file set scan.txt contents= "$wirelessList"

Now the issue with this is that it doesn’t populate the txt file with anything which makes me thing that wirelessList is empty. I’m not really sure where to go from here, so any help would be very appreciated.

I not check the logic, but the syntax , and is full of errors.

This is the correct version, but not the logic version:

:local wirelessList value="";
:set $wirelessList value=[/interface wireless scan wlan1 duration=7];
:log info message="Saving scan to file";
/file print file="scan.txt";
/file set "scan.txt" contents=$wirelessList;

The logic are wrong: you can not save scan results to file.