代码之家  ›  专栏  ›  技术社区  ›  Chris

没有在每次运行脚本时正确设置AppleScript剪贴板

  •  0
  • Chris  · 技术社区  · 7 年前

    我有一个正在运行的AppleScript,它将当前剪贴板保存到一个临时变量中,将剪贴板设置为其他对象(在本例中为表情符号),将剪贴板粘贴到字段中,然后将剪贴板恢复到运行脚本之前的状态。

    set temp to the clipboard
    set the clipboard to "🤔"
    tell application "System Events"
        keystroke "v" using command down
    end tell
    set the clipboard to temp
    

    它在第一次运行时工作正常,但如果运行两次或两次以上,它将在第一次粘贴表情符号,然后每隔一次粘贴一次原始剪贴板。

    1 回复  |  直到 7 年前
        1
  •  0
  •   wch1zpink    7 年前

    我可以通过增加延迟来解决我这边的问题。。。

    set temp to the clipboard
    set the clipboard to "🤔"
    tell application "System Events"
        keystroke "v" using command down
        delay 0.3
    end tell
    set the clipboard to temp