首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过applescript在洗牌或重复模式下设置iTunes 11

如何通过applescript在洗牌或重复模式下设置iTunes 11
EN

Stack Overflow用户
提问于 2013-02-03 16:16:05
回答 7查看 8.5K关注 0票数 7

根据http://dougscripts.com/,通过applescript设置、洗牌和重复模式在iTunes 11中是中断的。

根据这个说法,stackoverflow回答洗牌现在是一个独立播放列表的设置。

因此,我试图通过用户界面设置洗牌值,无论是通过iTunes的LCD-ish显示还是通过菜单栏。我所能得到的是“未知的UI索引”错误时,试图单击洗牌按钮/菜单项,无论是在LCD区域或菜单栏。(我对applescript还不熟悉)。

如果你们中的一些人能想出一种在iTunes 11上切换洗牌模式的方法,那就太好了。另外,我更喜欢基于菜单栏的解决方案,而不是液晶显示,因为洗牌按钮在后者中并不总是可见的。

理想情况下,我更喜欢基于语义的解决方案,而不是基于UI的解决方案,但我不确定它是否可行(iTunes 11 applescript库似乎过时了,因为它提到了“播放列表”项的“洗牌”属性)。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2013-02-04 01:38:13

我非常喜欢John的方法,我用他的方法为这些属性编写了一些getter/setter。它工作得很好,因为在使用它们之前不需要激活iTunes。不管怎么说,我想我应该把它们发出去,以防对任何人有帮助。您将使用“type”(根据菜单项名称建模)获取或设置它们的值,如下所示:

重复类型有"Off“、"All”或"One“。

洗牌类型有"Off“、”按歌曲“、”按专辑“或”按分组“。

代码语言:javascript
复制
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
票数 3
EN

Stack Overflow用户

发布于 2017-05-12 16:00:19

对于新的音乐应用程序,这是可行的。如果您仍在使用iTunes,请将“音乐”改为"iTunes“。

重复可以设置为oneoffall

代码语言:javascript
复制
tell application "Music"
   set song repeat to off
end

洗牌可以设置为false

代码语言:javascript
复制
tell application "Music"
   set shuffle enabled to true
end

您可以在道格脚本上找到更多详细信息。

票数 6
EN

Stack Overflow用户

发布于 2013-02-03 18:12:56

当我看到AppleScript属性current playlist的iTunes应用程序时,我是乐观的,但它不能很好地工作。它能够获取和设置当前播放列表的名称,但它不能用于属性shufflesong repeat。它在尝试设置任何属性时都会出错,并且它总是返回shuffle的'false‘和song repeat的'off’。

我认为您唯一的选择是UI脚本。下面是如何在菜单栏中切换洗牌:

代码语言:javascript
复制
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")

下面是如何设置重复:

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14674517

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档