LoginSignup
1
1

More than 5 years have passed since last update.

iTunes で再生中のトラック情報を、 Tweetbot の新規ツイートにコピペする Applescript

Last updated at Posted at 2013-06-15

お世話になってた #NowPlaying ウィジェットがAPI1.0で使えなくなったため、Applescript でごにょごにょしてみた。

Tweetbot が Applescript に対応していないため、 iTunes でトラック情報をクリップボードに収めてから、 Tweetbot をアクティブにしてショートカットを実行するという力技。アプリケーションとして保存して、 Alfred とかで呼び出せば OK。クリップボードの中身を書き換えるので、作業中に使う時は注意。

Tweetbot の部分を書き換えれば、他の Twitter クライアントでも行けるはず。(公式の Twitter.app はApplescript に対応してるので、クリップボードを使わなくていいかも)

if application "iTunes" is running and application "Tweetbot" is running then
    tell application "iTunes"
        if player state is playing or player state is paused then

            set nowPlayingTrack to current track
            set theAlbum to album of nowPlayingTrack
            set theAlbumArtist to album artist of nowPlayingTrack
            if theAlbumArtist is "" then
                set theAlbumArtist to artist of nowPlayingTrack
            end if
            set theSong to name of nowPlayingTrack
            set the clipboard to "♪" & theSong & " - " & theAlbumArtist & ": " & theAlbum & " #nowPlaying"

            tell application "Tweetbot"
                activate
            end tell

            tell application "System Events" to keystroke "n" using command down -- New Tweet
            tell application "System Events" to keystroke "v" using command down -- Paste
            tell application "System Events" to keystroke "a" using command down -- Select All

        end if
    end tell
end if
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1