Show the Dock with AppleScript?
[edit after more research]


You can use Applescript to turn on and off the dock's autohide.
You can't use Applescript to determine whether you have open/visible windows. This is because Applescript treats each application as an object, and some applications handle windows differently, meaning they can't all be manipulated or detected. I haven't even been able to find an applescript that can reliably count open windows, and there's absolutely no recent documentation on how to handle spaces with applescript.


From within the Script Editor, select File > Open Dictionary, and you will be presented with a list of applications that have dictionaries of scriptable objects &amp; behaviors that you can access. You want to select System Events and search for "dock". The dock preferences object has the property autohide, which looks like a good bet to do what you want: i.e. turn on autohide when there are open windows, and turn it off when there aren't. You can find more information about what's available by looking through different dictionaries and reading the documentation.

Apple's own introduction