Can I configure a task to run while my MacBook lid is closed?
While the lid is closed, a pmset wake will only wake up your machine very briefly, after which it will go back to sleep again. To keep the machine awake long enough to preform a task, you can caffeinate the machine for the amount of time (in seconds) you expect the task to take. For example, to keep the machine awake for 2 minutes, simply add

caffeinate -t 120 &amp;


early on in the script that runs your task.

Alternatively, caffeinate has options for tying the duration of the forced wake period to the completion of the task, but this runs the risk of keeping the machine awake indefinitely, so a safer bet is this expected-time-based approach.