if you're using CS6+, you can use:
i played around a little bit trying to turn off the dialog box.. but i've never had much luck with that.
OK, thanks, I didn't know this useful function app.executeMenuCommand.
What a pity the dialog box of Expand can't be turned off. I wanted to script that in order to do this operation completely transparently for the user.
the dialog box probably can be turned off. i just have never had much need for it, so i'm not 100% clear on it's usage and limitations. I'm sure one of the much much smarter people in this community can help with that issue. As i said though, you can use an action to perform the task, and the actions panel does give you the option to turn off the dialog.