iTunes用AppleScriptサンプルアップ
2007/10/26 (金) カテゴリー/AppleScript
えー、以前ご紹介したAppleScriptのエントリー。アクセスログを見てみると、
「なんかこの記事意外と人気あるなあ」
ということで、サーバの容量制限で削除されてしまっていたサンプルファイルを別サーバにアップしました。ダウンロード再開ということでお知らせです。てか削除されてから既に数ヶ月が経過しているんですがね(^^;
「なんかこの記事意外と人気あるなあ」
ということで、サーバの容量制限で削除されてしまっていたサンプルファイルを別サーバにアップしました。ダウンロード再開ということでお知らせです。てか削除されてから既に数ヶ月が経過しているんですがね(^^;
コメント(0) | トラックバック(0) | ↑ページトップ
iTunesでAppleScriptのお勉強
2006/05/08 (月) カテゴリー/AppleScript
なんだかいまさらながら AppleScript のお勉強をしてみた。まあ軟派な題材のほうが覚えが早いだろうということで、iTunesを題材にお勉強してみることにしました。
とりあえず スクリプトエディタを起動します。アプリのありかは「起動ディスク→アプリケーションフォルダ→AppleScript→スクリプトエディタ.app」ですね。
起動したら表示された画面に早速以下を入力、
それでは次はこれらのコマンドを複合したものに挑戦してみます。目指すは指定した曲の再生ができるようにすることです。
「プレイリストの選択はようわからんのよ」
みたいなことが書き込まれていたので、このソースを参考に自分で試行錯誤しながらプレイリストの選択ができるようにしてみました。
「なんでそこまでやるの?」
という気がしないでもないですが、こんなことをしている理由の90%は仕事中にそっとiTunesを操作したいからです( ̄▽ ̄;
さあ、Apple Script ができたのでこいつを組み込んだリモコンアプリを作成。仕事中に操作するのでなるべく地味ぃ〜で貧弱な見た目とコンパクトさが命です。で完成したのがこいつです。

使ってみたいというかたやスクリプトのソースが欲しい方はこちらからどうぞ→DownLoad:iTunesCntrl+スクリプトソース
とりあえず スクリプトエディタを起動します。アプリのありかは「起動ディスク→アプリケーションフォルダ→AppleScript→スクリプトエディタ.app」ですね。
起動したら表示された画面に早速以下を入力、
tell application "iTunes"
play
end tell
実行ボタンをクリックするとiTuneで再生が始まります。このソースをみてピンと来た方、はいそうです。当然ストップはこれ。play
end tell
tell application "iTunes"
stop
end tell
さらに一時停止はこう。stop
end tell
tell application "iTunes"
pause
end tell
いやー、お手軽ですねえ。ついでに次のソースだと再生と一時停止が実行するたびに切り替わります。pause
end tell
tell application "iTunes"
playpause
end tell
はーい、こうなったらじゃんじゃん行きましょう。次は次曲再生。playpause
end tell
tell application "iTunes"
next track
end tell
再生中の曲の頭出し。next track
end tell
tell application "iTunes"
back track
end tell
一つ前の曲に戻る。back track
end tell
tell application "iTunes"
previous track
end tell
基本的にApple Scriptはゼロからのスタートだったので超簡単なスクリプトを羅列してみました。previous track
end tell
それでは次はこれらのコマンドを複合したものに挑戦してみます。目指すは指定した曲の再生ができるようにすることです。
tell application "iTunes"
try
set mainWindow to item 1 of browser windows
set _playlist to the view of mainWindow
set theSongs to the name of every track of _playlist
set songTitle to choose from list theSongs with prompt "Choose a song to play"
tell _playlist
set song to item 1 of (every track whose name contains the songTitle)
end tell
-- say "Now playing the song " & (name of song) & " by " & (artist of song) -- 洋楽ばかりならこっち
say "Now Playing Chosen Song"
play song
on error
return 0
end try
end tell
ちなみに上記はどこか海外のQ&Aらしき掲示板に掲載されていたスクリプトを参考(ほぼそのまま)に作成。実行すると現在再生中のプレイリストに含まれる曲がリスト表示で選択できます。さてこのソースの元となった掲示板に、try
set mainWindow to item 1 of browser windows
set _playlist to the view of mainWindow
set theSongs to the name of every track of _playlist
set songTitle to choose from list theSongs with prompt "Choose a song to play"
tell _playlist
set song to item 1 of (every track whose name contains the songTitle)
end tell
-- say "Now playing the song " & (name of song) & " by " & (artist of song) -- 洋楽ばかりならこっち
say "Now Playing Chosen Song"
play song
on error
return 0
end try
end tell
「プレイリストの選択はようわからんのよ」
みたいなことが書き込まれていたので、このソースを参考に自分で試行錯誤しながらプレイリストの選択ができるようにしてみました。
tell application "iTunes"
try
set mainWindow to name of playlists
set listTitle to choose from list mainWindow with prompt "Choose a song to playlist"
set song to item 1 of (playlists whose name contains the listTitle)
set nowview to item 1 of browser windows
set view of nowview to song
-- say "Now playing the song " & (name of song)
say "Now Playing Chosen playlist"
play song
on error
return 0
end try
end tell
奇妙奇天烈な AppleScript の文法に苦労しながらもなんとか完成。まあここまで自分でしておきながら、try
set mainWindow to name of playlists
set listTitle to choose from list mainWindow with prompt "Choose a song to playlist"
set song to item 1 of (playlists whose name contains the listTitle)
set nowview to item 1 of browser windows
set view of nowview to song
-- say "Now playing the song " & (name of song)
say "Now Playing Chosen playlist"
play song
on error
return 0
end try
end tell
「なんでそこまでやるの?」
という気がしないでもないですが、こんなことをしている理由の90%は仕事中にそっとiTunesを操作したいからです( ̄▽ ̄;
さあ、Apple Script ができたのでこいつを組み込んだリモコンアプリを作成。仕事中に操作するのでなるべく地味ぃ〜で貧弱な見た目とコンパクトさが命です。で完成したのがこいつです。

使ってみたいというかたやスクリプトのソースが欲しい方はこちらからどうぞ→DownLoad:iTunesCntrl+スクリプトソース
コメント(0) | トラックバック(0) | ↑ページトップ
| ホーム |

