Skip to content

Instantly share code, notes, and snippets.

@allieus
Last active December 10, 2015 03:38
Show Gist options
  • Save allieus/4375452 to your computer and use it in GitHub Desktop.
Save allieus/4375452 to your computer and use it in GitHub Desktop.
현재 재생 중인 iTunes 노래를 트윗할 수 있도록, 브라우저 창을 띄워줍니다.
#!/usr/local/bin/macruby
#
# http://merbist.com/2010/01/17/controlling-itunes-with-macruby/
#
# $ sdef /Applications/iTunes.app | sdp -fh --basename iTunes
# $ gen_bridge_metadata -c '-I.' iTunes.h > iTunes.bridgesupport
# $ macruby itunes_nowplaying_tweet.rb
#
framework 'Foundation'
framework 'ScriptingBridge'
require 'open-uri'
itunes = SBApplication.applicationWithBundleIdentifier("com.apple.itunes")
if itunes.isRunning
track = itunes.currentTrack
name = track.name
artist = track.artist || track.albumArtist
tweet = "#NowPlaying #{name}, #{artist}"
share_url = "http://twitter.com/home?status=#{URI::encode(tweet)}"
NSWorkspace.sharedWorkspace.openURL(NSURL.URLWithString(share_url))
else
puts "iTunes not working."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment