applescripttimecodes

Set up timecode in applescript


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.


Solution

  • 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".