据http://dougscripts.com/通过AppleScript的设置随机播放和重复模式在iTunes 11被打破。
按照这个计算器的答案洗牌现在是一个独立的播放列表设置。
因此,我试图经由UI来设置洗牌值,无论是由iTunes的LCD-ISH显示器或通过菜单栏。 所有我能得到试图点击洗牌按钮/菜单项时,无论是在LCD区域或菜单栏是“未知的UI指数”的错误。 (我是新来的AppleScript)。
如果你们当中有些人可能会想出一个办法来打开iTunes的11随机播放模式,那将是巨大的。 此外, 我宁愿基于菜单栏,而不是在LCD显示屏上一个解决方案 ,因为随机播放按钮并不总是在后者可见。
理想情况下, 我宁愿在基于UI的解决方案基于语义的解决方案 ,但我不知道是否有可能(如iTunes 11的AppleScript库似乎因为它提到的“播放列表”项的“洗牌”属性是过时)。
Answer 1:
我喜欢约翰·索尔的方法这么多,我写我自己使用他的方法,这些性能有一定的getter / setter方法。 它的作品很好,因为你没有使用它们之前激活的iTunes。 无论如何,我想我会张贴在他们的帮助下对任何人的情况下。 您将获得或使用“类型”(菜单项名称为蓝本),如下所示设置它们的值:
重复的类型是“关”,“全部”或“一”。
Shuffle的类型是“关”,“通过歌”,“通过相册”,或“按分组”
on getRepeatType() -- the return value is a string: Off/All/One
tell application "System Events"
tell process "iTunes"
set menuItems to menu items of menu bar 1's menu bar item "Controls"'s menu 1's menu item "Repeat"'s menu 1
set currentChoice to "unknown"
repeat with anItem in menuItems
try
set theResult to value of attribute "AXMenuItemMarkChar" of anItem
if theResult is not "" then
set currentChoice to name of anItem
exit repeat
end if
end try
end repeat
end tell
end tell
return currentChoice
end getRepeatType
on setRepeatType(repeatType) -- repeatType is a string: Off/All/One
set currentValue to my getRepeatType()
ignoring case
if currentValue is not repeatType then
tell application "System Events" to tell process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Repeat"'s menu 1
if repeatType is "all" then
perform action "AXPress" of menu item "All"
else if repeatType is "one" then
perform action "AXPress" of menu item "One"
else
perform action "AXPress" of menu item "Off"
end if
end tell
end if
end ignoring
end setRepeatType
on getShuffleType() -- the return value is a string: Off/By Songs/By Albums/By Groupings
tell application "System Events"
tell process "iTunes"
set menuItems to menu items of menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1
set onOffItemName to name of item 1 of menuItems
end tell
end tell
-- is shuffle off
ignoring case
if onOffItemName contains " on " then return "Off"
end ignoring
-- shuffle is on so find how we are shuffling
set currentChoice to "Unknown"
tell application "System Events"
tell process "iTunes"
repeat with i from 2 to count of menuItems
set anItem to item i of menuItems
try
set theResult to value of attribute "AXMenuItemMarkChar" of anItem
if theResult is not "" then
set currentChoice to name of anItem
exit repeat
end if
end try
end repeat
end tell
end tell
return currentChoice
end getShuffleType
on setShuffleType(shuffleType) -- shuffleType is a string: Off/By Songs/By Albums/By Groupings
set currentValue to my getShuffleType()
script subs
on toggleShuffleOnOff()
tell application "System Events" to perform action "AXPress" of (first menu item of process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1 whose name ends with "Shuffle")
end toggleShuffleOnOff
on pressBySongs()
tell application "System Events" to perform action "AXPress" of (first menu item of process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1 whose name ends with "Songs")
end pressBySongs
on pressByAlbums()
tell application "System Events" to perform action "AXPress" of (first menu item of process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1 whose name ends with "Albums")
end pressByAlbums
on pressByGroupings()
tell application "System Events" to perform action "AXPress" of (first menu item of process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1 whose name ends with "Groupings")
end pressByGroupings
end script
ignoring case
if shuffleType contains "off" then -- we have to make sure it's off
if currentValue does not contain "off" then subs's toggleShuffleOnOff()
else
-- make sure it's on
if currentValue contains "off" then subs's toggleShuffleOnOff()
-- select the shuffle menu item for the type
if shuffleType contains "song" and currentValue does not contain "song" then
subs's pressBySongs()
else if shuffleType contains "album" and currentValue does not contain "album" then
subs's pressByAlbums()
else if shuffleType contains "group" and currentValue does not contain "group" then
subs's pressByGroupings()
end if
end if
end ignoring
end setShuffleType
Answer 2:
对于iTunes 12.6这个工程:
重复现在可以切换或 关闭,或全部 。
tell application "iTunes"
set song repeat to off
end
Shuffle的可切换真或假 。
tell application "iTunes"
set shuffle enabled to true
end
你可以找到更多的细节Dougscripts
Answer 3:
我是乐观的,当我看到的AppleScript属性current playlist
iTunes应用程序,但它不能很好地工作。 这是能够获取和设置当前播放列表的名称,但它可以做到既不为性shuffle
或song repeat
。 尝试设置这两个属性,当它的错误,它总是返回“假”的shuffle
和“关”的song repeat
。
我认为你唯一的选择是UI脚本。 以下是如何通过菜单栏切换洗牌:
tell application "System Events" to perform action "AXPress" of (first menu item of process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Shuffle"'s menu 1 whose name ends with "Shuffle")
下面是如何设置重复:
tell application "System Events" to tell process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Repeat"'s menu 1
perform action "AXPress" of menu item "Off"
perform action "AXPress" of menu item "All"
perform action "AXPress" of menu item "One"
end tell
Answer 4:
对于iTunes 12,这个工程
tell application "System Events"
tell process "iTunes" to if exists then
click menu item "Albums" of menu "Shuffle" of menu item "Shuffle" of menu "Controls" of menu bar 1
end if
end tell
更改Albums
到Songs
, Groupings
, On
和Off
相应。
Answer 5:
这是另一种方法:
activate application "iTunes"
tell application "System Events"
tell process "iTunes"
click menu item 1 of menu 1 of menu item "Shuffle" of menu 1 of menu bar item "Controls" of menu bar 1
end tell
end tell
Answer 6:
它看起来像许多脚本在最新的iTunes被打破。 这里有两个工作:
tell application "System Events" to tell UI element "iTunes" of list 1 of process "Dock"
if not (exists) then return
perform action "AXShowMenu"
click menu item "Shuffle" of menu 1
end tell
这一个切换通过码头洗牌。 当您使用它你可以看Dock菜单的动画。
这一次通过菜单切换洗牌,无形中:
tell application "System Events"
tell application process "iTunes"
tell menu 1 of menu item "Shuffle" of menu "Controls" of menu bar 1
if (value of attribute "AXMenuItemMarkChar" of item 1 of menu items as string) = "✓" then
click menu item 2
else
click menu item 1
end if
end tell
end tell
end tell
与iTunes在后台这两甚至会工作。
Answer 7:
花了一些时间解构都在这个岗位模糊化的解决方案(这似乎不再工作),这里有一个更好的可读性和可定制的做法,与iTunes 12.1的工作原理:
tell application "System Events"
set itunesMenuBar to process "iTunes"'s first menu bar
set controlsMenu to itunesMenuBar's menu bar item "Controls"'s first menu
set shuffleMenu to controlsMenu's menu item "Shuffle"'s first menu
set shuffleOnMenuItem to shuffleMenu's menu item "On"
set shuffleSongsMenuItem to shuffleMenu's menu item "Songs"
tell process "iTunes"
click shuffleOnMenuItem
click shuffleSongsMenuItem
end tell
end tell
这将打开随机播放并设置为随机播放歌曲,而不是专辑,它应该是很明显的怎么改做其他事情。
文章来源: How to set iTunes 11 in shuffle or repeat mode via applescript