-
-
Save jonmagic/8075970 to your computer and use it in GitHub Desktop.
This file contains 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
#!/Library/RubyMotion/bin/ruby -wKUW0 | |
# if your using MacRuby you might change this to | |
# => #!/usr/bin/env macruby -wKUW0 | |
framework 'Foundation' | |
framework 'ScriptingBridge' | |
# the original is part of an arstechnica article by Ryan | |
# SOURCE: http://arstechnica.com/apple/2011/09/tutorial-os-x-automation-with-macruby-and-the-scripting-bridge/ | |
# this script with get your favourite songs and create a Evernote Note # German and English | |
evernote = SBApplication.applicationWithBundleIdentifier("com.evernote.Evernote") | |
iTunes = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes") | |
favsongs = iTunes.sources | |
.find {|s| s.name == "Library"} | |
.playlists.find { |p| p.name == "Meine Top 25" || p.name == "Top 25 Most Played" } | |
.tracks.find_all { |t| t.rating > 3 } | |
.sort { |t1,t2| t2.playedCount <=> t1.playedCount } | |
.map { |t| "<li>#{t.artist} - #{t.name} (#{t.playedCount})<li>" } | |
evernote = SBApplication.applicationWithBundleIdentifier("com.evernote.Evernote") | |
evernote.createNoteFromFile nil, | |
fromUrl: nil, | |
withText: nil, | |
withHtml: "<ol>#{favsongs.join("n")}</ol>", | |
withEnml: nil, | |
title: "Favorite songs on #{Time.now.strftime("%Y-%m-%d")}", | |
notebook: evernote.notebooks[0], | |
tags: nil, | |
attachments: nil, | |
created: nil |
This file contains 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
#!/Library/RubyMotion/bin/ruby -wKUW0 | |
# if your using MacRuby you might change this to | |
# => #!/usr/bin/env macruby -wKUW0 | |
framework 'Foundation' | |
framework 'ScriptingBridge' | |
# this script will create a playlist "Songs with Lyrics" which include songs that have lyrics | |
# if you have a big Library might take long....... | |
iTunes = SBApplication.applicationWithBundleIdentifier "com.apple.itunes" | |
lyrics = ITunesUserPlaylist.alloc.initWithProperties({name: "Songs with Lyrics"}) | |
iTunes.sources.first.userPlaylists << lyrics | |
tracks = iTunes.sources | |
.first | |
.userPlaylists | |
.select { |list| list.name == "Music"} | |
.first | |
.tracks | |
tracks.select { |track| track.lyrics != "" } | |
.map { |track| track.duplicateTo(lyrics)} |
This file contains 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
#!/Library/RubyMotion/bin/ruby -wKUW0 | |
# if your using MacRuby you might change this to | |
# => #!/usr/bin/env macruby -wKUW0 | |
framework 'Foundation' | |
framework 'ScriptingBridge' | |
# this script will read you first 5 unread emails | |
mail_app = SBApplication.applicationWithBundleIdentifier "com.apple.mail" | |
voice_type = "com.apple.speech.synthesis.voice.Alex" | |
@voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type) | |
unread = mail_app.inbox.messages[0..5].select { |mail| mail.readStatus == false } | |
content = unread.inject(NSString.string) do |text, mail| | |
puts "Sender: #{mail.sender}" | |
puts "Subject: #{mail.subject}" | |
text.stringByAppendingString "sender #{mail.sender}, subject #{mail.subject}.\n" | |
end | |
@voice.startSpeakingString(content) | |
NSRunLoop.currentRunLoop.runUntilDate(NSDate.dateWithTimeIntervalSinceNow(20.0)) |
This file contains 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
#!/Library/RubyMotion/bin/ruby -wKUW0 | |
# if your using MacRuby you might change this to | |
# => #!/usr/bin/env macruby -wKUW0 | |
framework 'Foundation' | |
framework 'ScriptingBridge' | |
# this script will get the Open, High and close price of the Apple stocks of this year | |
# will put in a numbers table and after that create an Chart | |
numbers_app = SBApplication.applicationWithBundleIdentifier "com.apple.iwork.numbers" | |
# System Events app | |
sys_events = SBApplication.applicationWithBundleIdentifier "com.apple.systemevents" | |
# get the numbers app process | |
apps_processes = sys_events.applicationProcesses | |
numbers_process = apps_processes.select { |process| process.shortName == 'Numbers' }[0] | |
# create an url request | |
url_string = "http://ichart.yahoo.com/table.csv?s=GOOG&a=0&b=1&c=2013&d=0&e=31&f=2014&g=m&ignore=.csv" | |
url = NSURL.URLWithString url_string | |
csv = NSData.dataWithContentsOfURL(url) | |
# wanna be csv parser | |
response = csv.to_str.split("\n").map { |row| row.split(",") } | |
# bring Numbers with to front | |
numbers_app.activate | |
# create a new file | |
numbers_process.menuBars.first.menuBarItems[2].menus[0].menuItems[0].clickAt(0) | |
# get the table | |
table = numbers_app.documents.first.sheets.first.tables.first | |
# table configuration [name, rowcount, columncount] | |
table.name = "Apple stock 2013" | |
table.rowCount = response.count | |
table.columnCount = 4 | |
# set title | |
table.rows[0].cells.each.with_index do |cell, idx| | |
cell.value = response[0][idx] | |
end | |
date_formatter = NSDateFormatter.new | |
date_formatter.dateFormat = "MMMM YYYY" | |
# fill the cells | |
table.rows[1..-1].zip(response[1..-1]) do |row, content| | |
row.cells[0].value = date_formatter.stringFromDate NSDate.dateWithNaturalLanguageString(content[0]) | |
row.cells[1].value = content[1].gsub('.', ',') | |
row.cells[2].value = content[2].gsub('.', ',') | |
row.cells[3].value = content[3].gsub('.', ',') | |
end | |
# select cells | |
table.setSelectionRange table.cellRange | |
# create charts | |
numbers_process.menuBars.first.menuBarItems[4].menus[0].menuItems[3].menus[0].menuItems[1].clickAt(1) |
This file contains 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
#!/Library/RubyMotion/bin/ruby -wKUW0 | |
# if your using MacRuby you might change this to | |
# => #!/usr/bin/env macruby -wKUW0 | |
framework 'Foundation' | |
framework 'ScriptingBridge' | |
mail_app = SBApplication.applicationWithBundleIdentifier "com.apple.mail" | |
properties = { | |
subject: "Hello From Script", | |
content: "HAHAHAHAHAHAHAHHA" | |
} | |
mail = MailOutgoingMessage.alloc.initWithProperties properties | |
mail_app.outgoingMessages << mail | |
recipient = MailToRecipient.alloc.initWithProperties({ name: "Mateus", address: "[email protected]" } | |
mail.toRecipients << recipient | |
mail.setSender "[email protected]" | |
attachment = MailAttachment.alloc.initWithProperties Hash[:fileName, __FILE__ ] | |
# add it to the list of attachments | |
mail.content.paragraphs << attachment | |
mail.setVisible true | |
mail_app.activate | |
puts "sent" if mail.send | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment