0

I use applescript to remote Aegisub to shift the Video subtitle timeline by time. Please see the picture. here is the "shift by" window.

here is the code I use:

tell application "Aegisub"
    activate
    delay 0.1
end tell
tell application "System Events"
    tell process "Aegisub"
        keystroke "i" using command down   --cmd+i open "shift by" window
        delay 0.3
        click radio button "Time: " of window "Shift Times"   --choose shift by time not frames
        delay 0.3
        set the value of text field 1 of window "Shift Times" to "0:00:00.20" --set up shift how long time
        click radio button "Forward" of window "Shift Times"    --forward or backward
        click radio button "Selection onward" of group "Affect" of window "Shift Times"
        delay 0.3
        click button "OK" of window "Shift Times"
    end tell
end tell

note the line:

set the value of text field 1 of window "Shift Times" to "0:00:00.20"

It does change the on screen value of text field 1 to "0:00:00.20". But actually it will shift time by the last value you used.
If you input "0:00:00.20" with keyboard by hand, it will shift by time "0:00:00.20". Only this line doesn't work here. It looks like it's related to the format of the timecode. Note the timecode the app uses is "0:00:00.20", not "0:00:00:20". Hope someone can help me.

Cai Yu
  • 133
  • 1
  • 7

2 Answers2

0

When you enter a value into a text input box (depending on the attentiveness of the person who programmed the interface), the value may not be sent from the interface to the underlying model until the moment that the text input box loses focus: e.g., when the return key is typed, of another UI element is clicked. That focus shift may or may not happen (or may not happen in the same way) when you are scripting the interface, so you might want to invoke it directly, like so:

    set the value of text field 1 of window "Shift Times" to "0:00:00.20" --set up shift how long time
    click radio button "Forward" of window "Shift Times" --forward or backward
    click radio button "Selection onward" of group "Affect" of window "Shift Times"
    delay 0.3
    tell button "OK" of window "Shift Times"
        set focused to true
        click
    end tell
Ted Wrigley
  • 2,921
  • 2
  • 7
  • 17
0

Finally I find the answer. I need to use keystroke to input the value one digit by one digit, like what i do with keyboard. And the tell end tell structure for Button "OK" in @Ted Wrigley 's answer inspired me. Here the correct code

tell application "Aegisub"
    activate
    delay 0.1
end tell
tell application "System Events"
    tell process "Aegisub"
        set stime to "0000020"

        keystroke "i" using command down --cmd+i open "shift by" window
        delay 0.3
        click radio button "Time: " of window "Shift Times" --choose shift by time not frames
        delay 0.3

        tell text field 1 of window "Shift Times"
            set focused to true
            keystroke stime
        end tell

        click radio button "Forward" of window "Shift Times" --forward or backward
        click radio button "Selection onward" of group "Affect" of window "Shift Times"
        delay 0.3
        click button "OK" of window "Shift Times"
    end tell
end tell

note the format of timecode on screen is "0:00:00.20", but the format of stime must be "0000020".

Cai Yu
  • 133
  • 1
  • 7