iTunes 11でシャッフルのオン⇔オフをトグルするAppleScript
iTunes 11より前のバージョンのiTunesではプレイリスト単位でシャッフルするかどうか設定でき、シャッフルの設定を操作するAppleScriptも下記のような簡単な物ですみました。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "iTunes" | |
set shuffle of library playlist to false | |
end tell |
しかしiTunes 11にはプレイリスト単位のシャッフル機能はなく上記のコードではエラーがでてしまうので、iTunes 11用のシャッフルのオン⇔オフをトグルするAppleScriptを考えました。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check() | |
tell application "System Events" | |
tell process "iTunes" | |
click menu bar 1's menu bar item 6's menu 1's menu item 15's menu 1's menu item 1 | |
end tell | |
end tell | |
on check() --via http://d.hatena.ne.jp/zariganitosh/20090218/1235018953 | |
tell application "System Events" | |
if UI elements enabled is false then | |
tell application "System Preferences" | |
activate | |
set current pane to pane "com.apple.preference.universalaccess" | |
set msg to "GUIスクリプティングが利用可能になっていません。 | |
\"補助装置にアクセスできるようにする\" にチェックを入れて続けますか?" | |
display dialog msg buttons {"キャンセル", "チェックを入れて続ける"} with icon note default button 2 | |
end tell | |
set UI elements enabled to true | |
delay 1 | |
tell application "System Preferences" to quit | |
delay 1 | |
end if | |
end tell | |
end check |
How to set iTunes 11 in shuffle or repeat mode via applescriptという記事のAppleScriptを日本語環境でも動くように修正・簡略化し、GUIスクリプティングの判定をザリガニが見ていた…。さんからお借りしただけです。
AlfredやLaunchBarなどのランチャーからシャッフルのオン⇔オフを切り替えられて便利。
iTunesのメニューアイテムを操作するAppleScriptなので、iTunesバージョンアップによりメニューアイテムの構成が変わったら動かなくなります。