iTunes と QuickTime Player を AppleScript で連係させよう。

曲をコピーしたりする時は QuickTime Player Pro を使っています。


速度を落としたりできるので便利です。軽いし。音楽ファイルは iTunes で管理しているので、ディスクの階層を辿ってファイルを開くよりも、iTunes から直接 QuickTime Player で開いた方が、手間が省けるわけです。別に QuickTime Player でなくてもイケるかも。

再生中と選択中(複数でも)の場合の2パターンを考えてみました。

set tune_now to the current track

で演奏中のトラックを取得。

set tune_path to (the location of tune_now)

で演奏中の曲のファイルパスを取得。

if player state is not playing then set tune_path to ""

停止中の場合にファイルパスをリセット。

選択中の曲の場合は

set tunes_selected to the selection of browser window 1

で選択された曲のリストを取得。

set tune_path to (the location of item 1 of tunes_selected)

で選択された最初の曲のファイルパスを取得。複数選択されている場合もあるかな?と。ないか...。

こんな感じで書いてみました。


try
	tell application "iTunes"
		activate
		
		try
			set tune_now to the current track
			set tune_path to (the location of tune_now)
			if player state is not playing then set tune_path to ""
		on error
			set tune_path to ""
		end try
		
		if tune_path is "" then
			set tunes_selected to the selection of browser window 1
			if tunes_selected is {} then error "曲が選択されていません。"
			set tune_path to (the location of item 1 of tunes_selected)
		end if
	end tell
	
	tell application "QuickTime Player"
		activate
		open (tune_path)
	end tell
	
on error error_message number error_number
	if the error_number is not -128 then
		tell application "iTunes"
			beep
			display dialog error_message buttons {"OK"} default button 1
		end tell
	end if
end try

ファインダーでファイルを表示するならこう挿入すれば OK。


tell application "Finder"
	activate
	reveal tune_path
end tell
2008年05月11日 (日) at 11:47



1年前の同日エントリ 2年前の同日エントリ 3年前の同日エントリ 4年前の同日エントリ 5年前の同日エントリ 6年前の同日エントリ