【问题标题】:Running applescript while screen saver is activated在激活屏幕保护程序时运行 applescript
【发布时间】:2017-09-17 21:35:50
【问题描述】:

我想在某个时间播放 iTunes 文件夹播放列表,我自己想出了这部分。 但问题是,我想在之后将 iTunes 切换到迷你播放器。这是代码

tell application "iTunes" to quit
delay 5

tell application "iTunes"
    reopen
    activate
    set song repeat to all
    set shuffle enabled to true
    set sound volume to 35
    delay 5
    get name of AirPlay devices
    set selected of AirPlay device "Airport Express" to true
    play playlist "mom's music"
end tell

delay 20

-- here comes the part I don't get

tell application "System Events"
    tell process "iTunes"
        set frontmost to true
        if title of window 1 is "미니 플레이어" then
            click menu item 9 of menu 9 of menu bar 1
            delay 5
            click menu item 9 of menu 9 of menu bar 1
        else
            click menu item 9 of menu 9 of menu bar 1
        end if
    end tell
end tell

不要介意上面的部分。请查看“系统事件”部分。

当屏幕保护程序未运行时,它确实按预期工作,但在屏幕保护程序运行时它不工作,但我无法弄清楚我错过了什么。

那么,在我不知道的屏幕保护程序下运行 applescript 是否还有其他限制?任何建议,将不胜感激。谢谢。


2017-09-17 添加

当我按下“窗口”菜单项时,我注意到iTunes(主窗口)消失了。这是否意味着我必须超越屏幕保护程序才能通过 applescript 对 windows 进行任何操作?

【问题讨论】:

    标签: applescript


    【解决方案1】:

    似乎当屏幕保护程序运行时,脚本仍会运行但不处理某些事件。在这种情况下,解决方法是在运行任何依赖于 UI 脚本的代码之前停止屏幕保护程序。

    例子:

    tell application "System Events"
        key code 53 -- # Esc key.
        delay 1 - # Adjust as necessary, the screen saver needs to have stopped before continuing.
        tell process "iTunes"
            set frontmost to true
            if title of window 1 is "미니 플레이어" then
                click menu item 9 of menu 9 of menu bar 1
                delay 5
                click menu item 9 of menu 9 of menu bar 1
            else
                click menu item 9 of menu 9 of menu bar 1
            end if
        end tell
    end tell
    

    【讨论】:

    • 感谢您的建议。它在我的 mac mini 和 macbook air 上都不起作用。难道是因为ESC键不足以停止屏幕保护程序?再次非常感谢你:)
    【解决方案2】:

    试试这个版本

    try
        tell application id "com.apple.ScreenSaver.Engine" to quit
    end try
    
    tell application "System Events"
        tell process "iTunes"
            set frontmost to true
            if title of window 1 is "미니 플레이어" then
                click menu item 9 of menu 9 of menu bar 1
                delay 5
                click menu item 9 of menu 9 of menu bar 1
            else
                click menu item 9 of menu 9 of menu bar 1
            end if
        end tell
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多