7

http://dougscripts.com/によると、AppleScriptを介したシャッフルモードとリピートモードの設定は、iTunes11では機能しません。

このstackoverflowの回答によると、シャッフルはプレイリストに依存しない設定になりました。

そのため、iTunesのLCD風のディスプレイまたはメニューバーのいずれかを使用して、UIを介してシャッフル値を設定しようとしました。LCD領域またはメニューバーのいずれかでシャッフルボタン/メニュー項目をクリックしようとすると、「不明なUIインデックス」エラーしか発生しませんでした。(私はapplescriptを初めて使用します)。

iTunes 11でシャッフルモードを切り替える方法を思いついた人がいたら、それは素晴らしいことです。また、LCDディスプレイではシャッフルボタンが常に表示されるとは限らないため、LCDディスプレイではなくメニューバーに基づくソリューションをお勧めします。

理想的には、UIベースのソリューションよりもセマンティックベースのソリューションの方が好きですが、それが可能かどうかはわかりません(iTunes 11のAppleScriptライブラリは、「プレイリスト」アイテムの「シャッフル」プロパティについて言及しているため、時代遅れのようです)。

4

7 に答える 7

3

iTunes アプリケーションの AppleScript プロパティを見たときは楽観的でしcurrent playlistたが、うまく機能しません。現在のプレイリストの名前を取得および設定できますが、プロパティshuffleまたはsong repeat. いずれかのプロパティを設定しようとするとエラーが発生し、常に 'false'shuffleと 'off' を返します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
于 2013-02-03T18:12:56.933 に答える
3

私は John Sauer のアプローチがとても気に入ったので、彼のアプローチを使用してこれらのプロパティのゲッター/セッターをいくつか書きました。それらを使用する前にiTunesをアクティブ化する必要がないため、うまく機能します. とにかく、誰かの役に立てばと思って投稿しました。次のように、「タイプ」(メニュー項目名をモデルにしたもの) を使用して値を取得または設定します。

繰り返しの種類は、「オフ」、「すべて」、または「1 回」です。

シャッフル タイプは、「オフ」、「曲別」、「アルバム別」、または「グループ別」です。

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
于 2013-02-04T01:38:13.783 に答える
2

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ます。SongsGroupingsOnOff

于 2015-05-17T19:28:22.583 に答える
1

最新の iTunes では、これらのスクリプトの多くが壊れているようです。作品は以下の2つです。

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 がバックグラウンドにある場合でも機能します。

于 2015-03-15T09:02:47.107 に答える
1

別のアプローチを次に示します。

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
于 2013-02-03T19:03:35.747 に答える
0

この投稿で難読化されたすべてのソリューション (もはや機能していないように見えます) を分解するのに時間を費やしました。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

これにより、シャッフルがオンになり、アルバムではなく曲をシャッフルするように設定されます。他のことを行うように変更する方法は明らかです。

于 2015-06-29T00:02:12.307 に答える