Jak ustawić iTunes 11 w trybie shuffle lub repeat za pomocą applescript
Zgodnie z http://dougscripts.com / Ustawianie trybów shuffle i repeat ZA POMOCĄ applescript jest zepsute w iTunes 11.
Zgodnie z tą odpowiedź stackoverflow shuffle jest teraz niezależnym ustawieniem listy odtwarzania.
Tak więc, próbowałem ustawić wartość shuffle poprzez interfejs użytkownika, albo przez wyświetlacz LCD iTunes lub poprzez pasek menu. Wszystko, co mogłem uzyskać, to błędy "nieznany indeks interfejsu użytkownika" podczas próby kliknięcia przycisku/elementu menu shuffle, w obszarze LCD lub na pasku menu. (Jestem nowy w applescript).
Jeśli ktoś z was mógłby wymyślić sposób na przełączenie trybu shuffle w iTunes 11 , byłoby świetnie. Również wolałbym rozwiązanie oparte na pasku menu, a nie na wyświetlaczu LCD, ponieważ przycisk shuffle nie zawsze jest widoczny w tym drugim.
Najlepiej, wolałbym rozwiązanie semantyczne niż rozwiązanie oparte na interfejsie użytkownika , ale nie jestem pewien, czy to możliwe (biblioteka applescript iTunes 11 wydaje się być przestarzała, ponieważ wspomina o właściwość "shuffle" dla pozycji "playlisty").
7 answers
Spodobało mi się podejście Johna Sauera tak bardzo, że napisałem sobie kilka getterów/setterów dla tych właściwości, używając jego podejścia. To działa dobrze, ponieważ nie musisz aktywować iTunes przed ich użyciem. W każdym razie, pomyślałem, że wyślę je na wypadek, gdyby komuś pomogły. Otrzymasz lub ustawisz ich wartości za pomocą "typów" (wzorowanych na nazwach elementów menu) w następujący sposób:
Typy powtórzeń to "Off", "All"Lub " One".
Są to: "Off", "by Songs", "By Albums" lub " By Grupy "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
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-04 01:38:13
Dla iTunes 12.6 działa to:
Powtórzenie może być teraz przełączone nalub Offlub Wszystkie.
tell application "iTunes"
set song repeat to off
end
Shuffle może być przełączane True lub False .
tell application "iTunes"
set shuffle enabled to true
end
Więcej szczegółów znajdziesz na stronie Dougscripts
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-12 16:00:19
Byłem optymistą, gdy zobaczyłem właściwość AppleScript current playlist
aplikacji iTunes, ale to nie działa dobrze. Jest w stanie pobrać i ustawić nazwę bieżącej listy odtwarzania, ale nie może tego zrobić dla właściwości shuffle
lub song repeat
. Błąd podczas próby ustawienia właściwości i zawsze zwraca "false" dla shuffle
i " off " dla song repeat
.
Myślę, że jedyną opcją jest tworzenie skryptów UI. Oto jak przełączyć shuffle na pasek menu:
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")
A oto jak ustawić repeat:
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
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-03 18:12:56
Dla iTunes 12 to działa
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
Zmień Albums
na Songs
, Groupings
, On
i Off
odpowiednio.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-05-17 19:28:22
Oto inne podejście:
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
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-02-03 19:03:35
Wygląda na to, że wiele z tych skryptów jest zepsutych w najnowszym iTunes. Oto dwie prace:
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
Ten przełącza shuffle przez Dock. Możesz oglądać animację Menu dokowania podczas korzystania z niego.
Ten włącza shuffle poprzez menu, niewidocznie:
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
Oba będą działać nawet z iTunes jest w tle.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-15 09:02:47
Spędziłem trochę czasu dekonstruując wszystkie zaciemnione rozwiązania w tym poście (które wydają się już nie działać), oto bardziej czytelne i konfigurowalne podejście, które działa z 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
To włączy funkcję shuffle i ustawi ją na shuffle piosenki zamiast albumów, i powinno być dość oczywiste, jak zmienić ją, aby robić inne rzeczy.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-06-29 00:02:12