0

我使用 applescript 远程 Aegisub 以按时间移动视频字幕时间线。请看图片。 这是“移位”窗口。

这是我使用的代码:

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

注意这一行:

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

它确实将文本字段 1 的屏幕值更改为“0:00:00.20”。但实际上它会按您使用的最后一个值移动时间。
如果您用键盘手动输入“0:00:00.20”,它将按时间“0:00:00.20”移动。只有这条线在这里不起作用。看起来它与时间码的格式有关。请注意,应用程序使用的时间码是“0:00:00.20”,而不是“0:00:00:20”。希望可以有人帮帮我。

4

2 回答 2

0

当您在文本输入框中输入值时(取决于编写界面的人的注意力),直到文本输入框失去焦点时,该值可能不会从界面发送到底层模型:例如,当return键入键时,单击另一个 UI 元素。当您编写界面脚本时,这种焦点转移可能会发生也可能不会发生(或者可能不会以相同的方式发生),因此您可能希望直接调用它,如下所示:

    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
于 2020-02-26T17:46:57.917 回答
0

最后我找到了答案。我需要使用击键来逐位输入值,就像我用键盘做的那样。@Ted Wrigley 的回答中 Button "OK" 的tell end tell 结构启发了我。这里是正确的代码

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

注意屏幕上时间码的格式是“0:00:00.20”,但时间的格式必须是“0000020”。

于 2020-02-27T01:25:40.710 回答