0

I've been told that, technically, you can't move a dialog in AppleScript. Amazingly, the following code works.

I'm running a script for InDesign that creates a dialog box. Opening a new AppleScript Editor window and running this code will move the dialog box:

tell application "System Events"
    tell application process "Adobe InDesign CS6"
        set position of window 1 to {1000, 400}
    end tell
end tell

The problem is: I can't figure out a way to incorporate this code directly into my original script -- it just doesn't work, no matter what I try or where I insert it into the code. I have to run it from AppleScript Editor

Any ideas?

1 Answers1

3

Dialog boxes are usually blocking in the host application. You can certainly tell System Events to move a window, but Adobe InDesign itself is busy throwing up a blocking dialog box at the time, so it can't move its own dialog box.

If you want to get clever, you can fork off a process at the correct time and with the magically correct delays to move your dialog for you. This would be something like

do shell script "osascript -e 'delay 4' -e " & (quoted form of "tell application \"System Events\" to tell application process \"Adobe InDesign CS6\" to set position of window 1 to {1000, 400}") & " > /dev/null 2>&1 &"

Customize the delay as needed. This will be a magical value you that will have to figure out. Depending your needs, you might be able to put in a test to see if the dialog has disappeared before the script continues.

The bit at the end, > /dev/null 2>&1 &, tells bash to redirect stdout to /dev/null (junk it) and redirects stderr to stdout, then tells the whole command to run in the background. Without this entire chunk, this statement will block AppleScript from continuing until the shell script finishes executing.