Rhythm & Biology

Engineering, Science, et al.

AppleScriptでアプリケーションが起動中か調べる

applescriptを使えば、例えばitunesラジオで再生中の曲情報を調べたりできます。

tell application "iTunes"
  current stream title
end tell

ただ、itunesが起動してなかった場合にも、一度起動してから"missing value"を返してきます。そこで、まずitunesが起動中かどうかを調べるコードも加えてみます。

if application "iTunes" is running
  tell application "iTunes"
    current stream title
  end tell
else
  "iTunes not running"
end if

これで、勝手にitunesが立ち上がることがなくなりました。