rubyosa19 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{extconf.rb → ext/rubyosa/extconf.rb} +5 -18
- data/ext/rubyosa/osx_intern.h +912 -0
- data/ext/rubyosa/osx_ruby.h +34 -0
- data/{src → ext/rubyosa}/rbosa.c +4 -31
- data/{src → ext/rubyosa}/rbosa.h +1 -1
- data/{src → ext/rubyosa}/rbosa_conv.c +5 -24
- data/{src → ext/rubyosa}/rbosa_err.c +0 -0
- data/{src → ext/rubyosa}/rbosa_sdef.c +0 -8
- data/{src/lib → lib/rubyosa}/rbosa.rb +55 -22
- data/{src/lib → lib/rubyosa}/rbosa_properties.rb +0 -0
- data/lib/rubyosa.rb +18 -0
- metadata +45 -78
- data/AUTHORS +0 -16
- data/COPYRIGHT +0 -25
- data/README.markdown +0 -61
- data/bin/rdoc-osa +0 -232
- data/data/rubyosa/rdoc_html.rb +0 -696
- data/sample/AddressBook/inspect.rb +0 -31
- data/sample/BBEdit/unix_script.rb +0 -19
- data/sample/Finder/show_desktop.rb +0 -10
- data/sample/Mail/get_selected_mail.rb +0 -14
- data/sample/Photoshop/new_doc.rb +0 -13
- data/sample/Photoshop/new_doc_with_text.rb +0 -34
- data/sample/QuickTime/play_all.rb +0 -30
- data/sample/TextEdit/hello_world.rb +0 -19
- data/sample/iChat/image.rb +0 -18
- data/sample/iChat/uptime.rb +0 -15
- data/sample/iTunes/artwork.rb +0 -14
- data/sample/iTunes/control.rb +0 -66
- data/sample/iTunes/fade_volume.rb +0 -23
- data/sample/iTunes/inspect.rb +0 -16
- data/sample/iTunes/name_that_tune.rb +0 -97
- data/sample/iTunes/tag_genre_lastfm.rb +0 -32
- data/sample/misc/sdef.rb +0 -37
@@ -1,19 +0,0 @@
|
|
1
|
-
# Ask BBEdit to run the uptime(1) command and get the result.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
puts 'Asking for uptime...'
|
7
|
-
|
8
|
-
bbedit = OSA.app('BBEdit')
|
9
|
-
|
10
|
-
bbedit.make(OSA::BBEdit::TextDocument).text = <<EOS
|
11
|
-
#!/bin/sh
|
12
|
-
uptime
|
13
|
-
EOS
|
14
|
-
|
15
|
-
bbedit.run_unix_script
|
16
|
-
|
17
|
-
output_doc = bbedit.text_documents.find { |x| x.name == 'Unix Script Output' }
|
18
|
-
|
19
|
-
puts output_doc.text.get
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# Lists the content of the Finder desktop.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
ary = OSA.app('Finder').desktop.entire_contents.get
|
7
|
-
ary.each do |x|
|
8
|
-
next unless x.is_a?(OSA::Finder::Item)
|
9
|
-
puts "#{x.class.name.sub(/^.+::/, '').sub(/_/, ' ').ljust(25)} #{x.name}"
|
10
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# Retrieve and show every selected message content in Mail into new TextEdit documents.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
OSA.utf8_strings = true
|
7
|
-
textedit = OSA.app('TextEdit')
|
8
|
-
mailApp = OSA.app('Mail')
|
9
|
-
viewers = mailApp.message_viewers
|
10
|
-
viewers.each do |viewer|
|
11
|
-
viewer.selected_messages.each do |message|
|
12
|
-
textedit.make(OSA::TextEdit::Document).text = message.content
|
13
|
-
end
|
14
|
-
end
|
data/sample/Photoshop/new_doc.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Creates a new Photoshop document with a given title and size.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
app = OSA.app('Adobe Photoshop CS2')
|
7
|
-
app.settings.ruler_units = OSA::AdobePhotoshopCS2::E440::PIXEL_UNITS
|
8
|
-
|
9
|
-
app.make(OSA::AdobePhotoshopCS2::Document, nil, :with_properties => {
|
10
|
-
:name => 'Ruby Rocks',
|
11
|
-
:width => 500,
|
12
|
-
:height => 500
|
13
|
-
})
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# Creates a new Photoshop document with a given title and size, and adds a text
|
2
|
-
# layer on it.
|
3
|
-
|
4
|
-
begin require 'rubygems'; rescue LoadError; end
|
5
|
-
require 'rbosa'
|
6
|
-
|
7
|
-
app = OSA.app('Adobe Photoshop CS2')
|
8
|
-
app.settings.ruler_units = OSA::AdobePhotoshopCS2::E440::PIXEL_UNITS
|
9
|
-
app.instance_eval do
|
10
|
-
def create_document(options = {})
|
11
|
-
make(OSA::AdobePhotoshopCS2::Document, nil, :with_properties => {
|
12
|
-
:name => 'Ruby Rocks',
|
13
|
-
:width => 500,
|
14
|
-
:height => 500
|
15
|
-
}.merge(options))
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_layer(name, kind)
|
19
|
-
kinds = %w(NORMAL GRADIENTFILL PATTERNFILL TEXT SOLIDFILL)
|
20
|
-
do_javascript %(
|
21
|
-
var doc = app.activeDocument;
|
22
|
-
var layer = doc.artLayers.add();
|
23
|
-
layer.name = "#{name || ''}";
|
24
|
-
layer.kind = LayerKind.#{kinds.detect {|k| k.downcase == kind} || 'NORMAL'};
|
25
|
-
)
|
26
|
-
current_document.art_layers[0]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
app.create_document(:name => 'Schweet')
|
31
|
-
layer = app.add_layer('A text layer', 'text')
|
32
|
-
texto = layer.text_object
|
33
|
-
texto.size = 40
|
34
|
-
texto.contents = "This is some text"
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# Opens given movies and in QuickTime and starts playing them indefinitely in fullscreen mode.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
if ARGV.empty?
|
7
|
-
STDERR.puts "Usage: #{$0} <movies-files>"
|
8
|
-
exit 1
|
9
|
-
end
|
10
|
-
|
11
|
-
app = OSA.app('QuickTime Player')
|
12
|
-
ARGV.each { |p| app.open(p) }
|
13
|
-
l = app.movies.to_a
|
14
|
-
exit if l.length == 0
|
15
|
-
last = nil
|
16
|
-
loop do
|
17
|
-
l2 = []
|
18
|
-
l.length.times { l2 << l.slice!(rand(l.length)) }
|
19
|
-
l2[0], l2[1] = l2[1], l2[0] if l2[0] == last and l2.length > 1 # not to have the same file playing twice consecutively
|
20
|
-
l2.each do |m|
|
21
|
-
m.rewind # to be sure that we start at the beginning of the movie
|
22
|
-
m.present
|
23
|
-
sleep 0.1 while m.playing?
|
24
|
-
m.stop # to be sure we are not in presentation mode anymore
|
25
|
-
# if we do not end with a stop, and the movie has been stopped by the user,
|
26
|
-
# the next present will not play the movie because an other movie is still in presentation mode
|
27
|
-
last = m
|
28
|
-
end
|
29
|
-
l = l2
|
30
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# Create new TextEdit documents with a 'Hello World' text.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
textedit = OSA.app('TextEdit')
|
7
|
-
|
8
|
-
# Complex way.
|
9
|
-
textedit.make(OSA::TextEdit::Document, :with_properties => {:text => 'Hello World #1'})
|
10
|
-
|
11
|
-
# Easier way.
|
12
|
-
textedit.make(OSA::TextEdit::Document).text = 'Hello World #2'
|
13
|
-
|
14
|
-
=begin
|
15
|
-
# Easiest way, not implemented for now.
|
16
|
-
document = OSA::TextEdit::Document.new
|
17
|
-
document.text = 'Hello World #3'
|
18
|
-
textedit << document
|
19
|
-
=end
|
data/sample/iChat/image.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# Periodically set your iChat image to one of the default images.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
ichat = OSA.app('iChat')
|
7
|
-
|
8
|
-
old_image = ichat.image
|
9
|
-
trap('INT') { ichat.image = old_image; exit 0 }
|
10
|
-
|
11
|
-
paths = Dir.glob("/Library/User Pictures/**/*.tif")
|
12
|
-
|
13
|
-
while true do
|
14
|
-
paths.each do |path|
|
15
|
-
ichat.image = File.read(path)
|
16
|
-
sleep 2
|
17
|
-
end
|
18
|
-
end
|
data/sample/iChat/uptime.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# Periodically set your iChat status to the output of uptime(1).
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
app = OSA.app('iChat')
|
7
|
-
previous_status_message = app.status_message
|
8
|
-
trap('INT') { app.status_message = previous_status_message; exit 0 }
|
9
|
-
while true
|
10
|
-
u = `uptime`
|
11
|
-
hours = u.scan(/^\s*(\d+:\d+)\s/).to_s + ' hours'
|
12
|
-
days = u.scan(/\d+\sdays/).to_s
|
13
|
-
app.status_message = "OSX up #{days} #{hours}"
|
14
|
-
sleep 5
|
15
|
-
end
|
data/sample/iTunes/artwork.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# Open the artwork of the current iTunes track in Preview.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
artworks = OSA.app('iTunes').current_track.artworks
|
7
|
-
if artworks.size == 0
|
8
|
-
puts "No artwork for current track."
|
9
|
-
exit 1
|
10
|
-
end
|
11
|
-
|
12
|
-
fname = '/tmp/foo.' + artworks[0].format.downcase.strip
|
13
|
-
File.open(fname, 'w') { |io| io.write(artworks[0].data) }
|
14
|
-
system("open -a Preview #{fname}")
|
data/sample/iTunes/control.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# Simple iTunes controller.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
require 'curses'
|
6
|
-
include Curses
|
7
|
-
|
8
|
-
app = OSA.app('iTunes')
|
9
|
-
OSA.utf8_strings = true
|
10
|
-
|
11
|
-
if app.current_track.nil?
|
12
|
-
# We don't support write access now, so...
|
13
|
-
puts "Please select a track in iTunes and retry again."
|
14
|
-
exit 1
|
15
|
-
end
|
16
|
-
|
17
|
-
init_screen
|
18
|
-
|
19
|
-
addstr <<EOS
|
20
|
-
Keys available:
|
21
|
-
SPACE toggle play/pause
|
22
|
-
p go to previous song
|
23
|
-
n go to next song
|
24
|
-
f toggle fast forward
|
25
|
-
r toggle rewind
|
26
|
-
m toggle mute
|
27
|
-
q exit the program
|
28
|
-
|
29
|
-
On track:
|
30
|
-
EOS
|
31
|
-
|
32
|
-
begin
|
33
|
-
noecho
|
34
|
-
while true
|
35
|
-
setpos(9, 2)
|
36
|
-
addstr "#{app.player_state.to_s.capitalize} : #{app.current_track.name}".ljust(cols - 3)
|
37
|
-
refresh
|
38
|
-
x = getch
|
39
|
-
case x.chr
|
40
|
-
when ' '
|
41
|
-
app.playpause
|
42
|
-
when 'p'
|
43
|
-
app.previous_track
|
44
|
-
when 'n'
|
45
|
-
app.next_track
|
46
|
-
when 'f'
|
47
|
-
if app.player_state == OSA::ITunes::EPLS::FAST_FORWARDING
|
48
|
-
app.resume
|
49
|
-
else
|
50
|
-
app.fast_forward
|
51
|
-
end
|
52
|
-
when 'r'
|
53
|
-
if app.player_state == OSA::ITunes::EPLS::REWINDING
|
54
|
-
app.resume
|
55
|
-
else
|
56
|
-
app.rewind
|
57
|
-
end
|
58
|
-
when 'm'
|
59
|
-
app.mute = !app.mute?
|
60
|
-
when 'q'
|
61
|
-
break
|
62
|
-
end
|
63
|
-
end
|
64
|
-
ensure
|
65
|
-
echo
|
66
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# Start playing, then fade the volume from 0 to the original setting.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
app = OSA.app('iTunes')
|
7
|
-
|
8
|
-
original_volume = app.sound_volume
|
9
|
-
|
10
|
-
if original_volume == 0 or app.current_track.nil?
|
11
|
-
puts "Please select a track and/or set a higher volume."
|
12
|
-
exit 1
|
13
|
-
end
|
14
|
-
|
15
|
-
app.sound_volume = 0
|
16
|
-
app.play
|
17
|
-
|
18
|
-
0.step(original_volume, original_volume / 8.0) do |volume|
|
19
|
-
app.sound_volume = volume
|
20
|
-
sleep(0.1)
|
21
|
-
end
|
22
|
-
|
23
|
-
app.sound_volume = original_volume
|
data/sample/iTunes/inspect.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# Quick inspection of iTunes' sources, playlists and tracks.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
app = OSA.app('iTunes')
|
7
|
-
OSA.utf8_strings = true
|
8
|
-
app.sources.each do |source|
|
9
|
-
puts source.name
|
10
|
-
source.playlists.each do |playlist|
|
11
|
-
puts " -> #{playlist.name}"
|
12
|
-
playlist.tracks.each do |track|
|
13
|
-
puts " -> #{track.name}" if track.enabled?
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# Plays a track of your iTunes library at random and asks you to guess the name of the track.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
|
6
|
-
OSA.app('iTunes') # initialize the constants
|
7
|
-
|
8
|
-
class OSA::ITunes::Application
|
9
|
-
|
10
|
-
def library_source
|
11
|
-
sources.find {|s| s.kind == OSA::ITunes::ESRC::LIBRARY }
|
12
|
-
end
|
13
|
-
|
14
|
-
def library
|
15
|
-
library_source.playlists.find {|p| p.name == 'Library' }
|
16
|
-
end
|
17
|
-
|
18
|
-
def party_shuffle
|
19
|
-
library_source.playlists.find {|p| p.special_kind == OSA::ITunes::ESPK::PARTY_SHUFFLE }
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
class OSA::ITunes::Playlist
|
25
|
-
|
26
|
-
def random_track
|
27
|
-
tracks[rand * tracks.size]
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
class OSA::ITunes::Track
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
"#{artist} - #{name}"
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
class NameThatTune
|
42
|
-
attr_accessor :score
|
43
|
-
|
44
|
-
def initialize
|
45
|
-
@itunes = OSA.app('iTunes')
|
46
|
-
end
|
47
|
-
|
48
|
-
def finish
|
49
|
-
puts "Thanks for playing! Score: #{score}"
|
50
|
-
exit
|
51
|
-
end
|
52
|
-
|
53
|
-
def start
|
54
|
-
@score = 0
|
55
|
-
while true
|
56
|
-
@itunes.party_shuffle.play
|
57
|
-
@itunes.next_track
|
58
|
-
|
59
|
-
options = generate_options
|
60
|
-
options.each_with_index { |track, i| puts "#{i+1} - #{track}" }
|
61
|
-
|
62
|
-
selected = gets.to_i
|
63
|
-
|
64
|
-
finish if selected == 0
|
65
|
-
|
66
|
-
if correct?(options, selected)
|
67
|
-
points = calculate_points_for_correct_choice
|
68
|
-
puts "Correct! #{points} points"
|
69
|
-
self.score += points
|
70
|
-
else
|
71
|
-
puts "Sorry! That was #{@itunes.current_track}"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def correct?(options, selected)
|
79
|
-
options[selected-1] == @itunes.current_track
|
80
|
-
end
|
81
|
-
|
82
|
-
def calculate_points_for_correct_choice
|
83
|
-
points = (@itunes.player_position > 10 ? 1 : 10 - @itunes.player_position) * 1000
|
84
|
-
points += (@itunes.current_track.played_count > 10 ? 1 : 10 - @itunes.current_track.played_count) * 100
|
85
|
-
points.to_i
|
86
|
-
end
|
87
|
-
|
88
|
-
def generate_options(count = 5)
|
89
|
-
options = []
|
90
|
-
options << @itunes.current_track
|
91
|
-
(count - 1).times {|i| options << @itunes.library.random_track }
|
92
|
-
options = options.sort_by { rand }
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
NameThatTune.new.start
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# For each selected track in iTunes, retrieve the genre from Last.fm and accordingly tag the track.
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
require 'net/http'
|
6
|
-
require 'cgi'
|
7
|
-
require 'rexml/document'
|
8
|
-
include REXML
|
9
|
-
|
10
|
-
itunes = OSA.app('iTunes')
|
11
|
-
|
12
|
-
selection = itunes.selection.get
|
13
|
-
if selection.empty?
|
14
|
-
$stderr.puts "Please select some tracks."
|
15
|
-
exit 1
|
16
|
-
end
|
17
|
-
|
18
|
-
first = selection.first.artist
|
19
|
-
feed = "http://ws.audioscrobbler.com/1.0/artist/#{CGI::escape(first)}/toptags.xml"
|
20
|
-
doc = Document.new(Net::HTTP.get(URI(feed)))
|
21
|
-
|
22
|
-
selection.each do |track|
|
23
|
-
if doc.root.attributes['artist'] == track.artist
|
24
|
-
genre = doc.root[1][1].text.capitalize
|
25
|
-
else
|
26
|
-
puts 'Querying Last.fm again...'
|
27
|
-
feed = "http://ws.audioscrobbler.com/1.0/artist/#{CGI::escape(track.artist)}/toptags.xml"
|
28
|
-
doc = Document.new(Net::HTTP.get(URI(feed)))
|
29
|
-
genre = doc.root[1][1].text.capitalize
|
30
|
-
end
|
31
|
-
track.genre = genre
|
32
|
-
end
|
data/sample/misc/sdef.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# Print the given application's sdef(5).
|
2
|
-
|
3
|
-
begin require 'rubygems'; rescue LoadError; end
|
4
|
-
require 'rbosa'
|
5
|
-
require 'rexml/document'
|
6
|
-
|
7
|
-
def usage
|
8
|
-
STDERR.puts <<-EOS
|
9
|
-
Usage: #{$0} [--name | --path | --bundle_id | --signature] ...
|
10
|
-
Examples:
|
11
|
-
#{$0} --name iTunes
|
12
|
-
#{$0} --path /Applications/iTunes.app
|
13
|
-
#{$0} --bundle_id com.apple.iTunes
|
14
|
-
#{$0} --signature hook
|
15
|
-
EOS
|
16
|
-
exit 1
|
17
|
-
end
|
18
|
-
|
19
|
-
usage unless ARGV.length == 2
|
20
|
-
|
21
|
-
key = case ARGV.first
|
22
|
-
when '--name'
|
23
|
-
:name
|
24
|
-
when '--path'
|
25
|
-
:path
|
26
|
-
when '--bundle_id'
|
27
|
-
:bundle_id
|
28
|
-
when '--signature'
|
29
|
-
:signature
|
30
|
-
else
|
31
|
-
usage
|
32
|
-
end
|
33
|
-
|
34
|
-
app = OSA.app(key => ARGV.last)
|
35
|
-
doc = REXML::Document.new(app.sdef)
|
36
|
-
doc.write(STDOUT, 0)
|
37
|
-
puts ""
|