【问题标题】:Applescript clicking unknown menu item?Applescript单击未知菜单项?
【发布时间】:2021-11-25 01:39:34
【问题描述】:

我正在使用 LG OnScreen Control 应用程序在使用图片时在菜单项中没有名称的不同显示器布局之间切换。我想写一个applescript,点击第一个或第9个,我最喜欢的选择。 =)

我怎样才能点击它们?我只能用下面的代码来选择它们

ignoring application responses
    tell application "System Events" to tell process "OnScreen Control"
        click menu bar item 1 of menu bar 2
    end tell
end ignoring
delay 0.1
do shell script "killall System\\ Events"

tell application "System Events" to tell process "OnScreen Control"
    tell menu bar item 1 of menu bar 2
        click menu item "Screen Split" of menu 1
    end tell
end tell

UPDATE1:啊,我真傻,我想我可以使用“key code 125”多次单击向下箭头,然后使用“key code 76”回车。

ignoring application responses
    tell application "System Events" to tell process "OnScreen Control"
        click menu bar item 1 of menu bar 2
    end tell
end ignoring
delay 0.1
do shell script "killall System\\ Events"

tell application "System Events" to tell process "OnScreen Control"
    tell menu bar item 1 of menu bar 2
        click menu item "Screen Split" of menu 1
        key code 125
        key code 125
        key code 125
        key code 125
        key code 125
        key code 125
        key code 125
        key code 125
        key code 76
    end tell
end tell

想知道是否有更好更快的方法来执行此操作?尽管没有名称,但直接解决子项目?

UDPATE2感谢@user3439894

ignoring application responses
    tell application "System Events" to tell process "OnScreen Control"
        click menu bar item 1 of menu bar 2
    end tell
end ignoring
delay 0.1
do shell script "killall System\\ Events"

tell application "System Events" to tell process "OnScreen Control"
    tell menu bar item 1 of menu bar 2
        click menu item "Screen Split" of menu 1
        click menu item 9 of menu 1 of menu item "Screen Split" of menu 1
    end tell
end tell

【问题讨论】:

  • 我真傻,我想我可以使用“密钥代码 76”。想知道是否有更好更快的方法来执行此操作?

标签: macos menu applescript automator


【解决方案1】:

之后:

click menu item "Screen Split" of menu 1

用途:

click menu item 9 of menu 1 of menu item "Screen Split" of menu 1

摆脱所有key code 命令

【讨论】:

  • 很好,谢谢!学习菜单组合的菜单很棘手。 =) 我希望有一种方法可以做到这一点,而不会造成延迟并且可以直观地看到动作。你知道这是否可能吗? (可能会打开另一个问题,但很好奇)
  • RE:“我希望有一种方法可以在没有延迟的情况下做同样的事情”,请参阅我对A: AppleScript - Can't get rid of delay after click 的回答,了解如何处理 延迟。 ——RE:“并在视觉上看到动作。你知道这是否可能吗?” -- 没有 LG 显示器我不能说,但是,我会看看它是否写入 .plist file,然后看看如何使用defaultscommand/usr/libexec/PlistBuddycommand
  • @Markus,请参阅上面的评论,谢谢。
  • 非常感谢,我已经尝试过使用 kill and delay 方法。我省略了第二次延迟,因为它似乎没有太大区别(如果没有第一个延迟,它甚至不会运行)。不过,我真的很喜欢你的解释,答案写得很好,太棒了,我学到了更多东西并给了你一个投票。只是想知道您是否发现 clickclick(或 mousetools)比 AppleScript 更快?我假设applescript在这里仍然是最好的。
  • 也感谢 .plist 文件的提示。我只在应用程序内容中找到了一个(库文件夹中没有),它看起来不像存储这些设置,并且在选择不同的布局时文件不会改变。我假设此功能是通过软件处理的,以便将窗口捕捉到这些布局,因此 .plist 仅在该功能由显示器的硬件处理时才有效。
猜你喜欢
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
  • 2012-04-11
  • 1970-01-01
  • 2019-03-21
  • 2022-06-23
  • 1970-01-01
  • 2011-02-18
相关资源
最近更新 更多