我想在特定时间播放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做任何事情?
答案 0 :(得分:0)
当屏幕保护程序运行时,脚本仍会运行但不会处理某些事件。解决方法是在运行任何依赖于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
答案 1 :(得分:0)
试试这个版本
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