Last active
December 10, 2015 03:38
-
-
Save allieus/4375452 to your computer and use it in GitHub Desktop.
현재 재생 중인 iTunes 노래를 트윗할 수 있도록, 브라우저 창을 띄워줍니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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