How to trick Mac to think it is plugged to wall?

I need to compact sparse disk image but i run in battery power. Now i get error when i try to do this.

How i can do this without plugging my Mac to wall?

do shell script "hdiutil compact " & my_path

AFAIK, there is no way to trick a Mac into thinking it is plugged in. I’m afraid you’ll just have to run your script while your Mac is plugged in. Sorry!