basilico 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Basilico
2
+
3
+ Basilico is an event handling framework for the Mac OS X Pomodoro application. You can hook it into the application using the Script section of Pomodoro Preferences. More on this below. While being a framework for events, it also provides useful events out of the box.
4
+
5
+ ## Requirements
6
+
7
+ Basilico runs on MacRuby. Actually the framework itself should run on any Ruby implementation (tests coming soon), but most of the built-in handlers use the `Basilico::AppHelpers` module which depends on some OS X frameworks.
8
+
9
+ ## Built-in handlers
10
+
11
+ ### Adium, iChat and Skype status and status message
12
+
13
+ These handlers update your status and status message when starting or ending a pomodoro. Your status will be set to "Do not disturb" or "Away" when starting a pomodoro with "in a Pomodoro" as the status message. Upon ending or resetting the pomodoro your status will be set back to "Online" or "Available" and your status message will be cleared.
14
+
15
+ ### Pomodoro logger
16
+
17
+ The logger event handler logs every event with the current time and all the arguments into the file `~/pomodoro.log`.
18
+
19
+ ## Setting up Basilico
20
+
21
+ You should have MacRuby installed. Then install the basilico gem:
22
+
23
+ $ gem install basilico
24
+
25
+ The only thing left is setting up the Pomodoro app to send events to Basilico. You will find example scripts in the `scripts` directory of the repository. Open the preferences window of Pomodoro and setup the scripts in the Scripts tab.
26
+
27
+ The example scripts use rvm. You can simplify them if you have MacRuby installed some other way.
28
+
29
+ ## License
30
+
31
+ (The MIT License)
32
+
33
+ Copyright (c) 2010 László Bácsi
34
+
35
+ Permission is hereby granted, free of charge, to any person obtaining
36
+ a copy of this software and associated documentation files (the
37
+ "Software"), to deal in the Software without restriction, including
38
+ without limitation the rights to use, copy, modify, merge, publish,
39
+ distribute, sublicense, and/or sell copies of the Software, and to
40
+ permit persons to whom the Software is furnished to do so, subject to
41
+ the following conditions:
42
+
43
+ The above copyright notice and this permission notice shall be
44
+ included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
47
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
48
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
49
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
50
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
51
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
52
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/basilico ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env macruby
2
+
3
+ require 'basilico'
4
+
5
+ event = ARGV.shift
6
+ unless Basilico::EVENTS.include?(event)
7
+ $stderr.puts "USAGE: #{File.basename(__FILE__)} event [key=value ...]"
8
+ $stderr.puts " where event is one of the following:"
9
+ $stderr.puts " #{Basilico::EVENTS.join(", ")}"
10
+ exit 1
11
+ end
12
+
13
+ Basilico.run_all(event, ARGV)
@@ -0,0 +1,46 @@
1
+ require 'basilico/app_helpers'
2
+
3
+ module Basilico
4
+ module Handlers
5
+ class AdiumStatus < Basilico::EventHandler
6
+
7
+ include Basilico::AppHelpers
8
+
9
+ def initialize
10
+ @adium = find_running_app_by_name("Adium")
11
+ end
12
+
13
+ def start(options={})
14
+ return unless running?
15
+ set_status_with_message "Away", "in a Pomodoro"
16
+ end
17
+
18
+ def end(options={})
19
+ return unless running?
20
+ set_status_with_message "Available", nil
21
+ end
22
+ alias_method :reset, :end
23
+
24
+ private
25
+
26
+ def running?
27
+ !!@adium
28
+ end
29
+
30
+ def set_status_with_message(status, message)
31
+ first_account = nil
32
+ @adium.accounts.select(&:enabled).each do |account|
33
+ #unless first_account
34
+ account.send("go#{status}WithMessage", message)
35
+ #first_account = account
36
+ #else
37
+ # This should work and works in other contexts
38
+ # but here it throws an exception
39
+ #account.setStatus(first_account.status)
40
+ #end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,52 @@
1
+ require 'basilico/app_helpers'
2
+
3
+ module Basilico
4
+ module Handlers
5
+ class IChatStatus < Basilico::EventHandler
6
+
7
+ include Basilico::AppHelpers
8
+
9
+ ICHAT_STATUSES = {
10
+ "available" => 1635148140,
11
+ "away" => 1635213689,
12
+ "invisible" => 1768846963,
13
+ "offline" => 1868981868
14
+ }
15
+
16
+ def initialize
17
+ @ichat = find_running_app_by_name("iChat")
18
+ end
19
+
20
+ def start(options={})
21
+ return unless running?
22
+ set_status "away"
23
+ set_status_message "in a Pomodoro"
24
+ end
25
+
26
+ def end(options={})
27
+ return unless running?
28
+ set_status "available"
29
+ set_status_message ""
30
+ end
31
+ alias_method :reset, :end
32
+
33
+ private
34
+
35
+ def running?
36
+ !!@ichat
37
+ end
38
+
39
+ def set_status(status)
40
+ status_id = ICHAT_STATUSES[status]
41
+ @ichat.setStatus(status_id)
42
+ # let's wait until the status has actually changed
43
+ until @ichat.status == status_id; end
44
+ end
45
+
46
+ def set_status_message(message)
47
+ @ichat.setStatusMessage(message)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+
3
+ module Basilico
4
+ module Handlers
5
+ class LogEvents < Basilico::EventHandler
6
+
7
+ Basilico::EVENTS.each do |event|
8
+ define_method(event) do |options|
9
+ log(event, options)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def log(event, options)
16
+ File.open(File.expand_path("~/pomodoro.log"), "a") do |f|
17
+ f.puts "[#{Time.now}] #{event.tr('_', ' ').capitalize}"
18
+ f.puts YAML.dump(options).gsub(/\A--- \n/, '').gsub(/^/, ' ') unless options.empty?
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ require 'basilico/app_helpers'
2
+
3
+ module Basilico
4
+ module Handlers
5
+ class SkypeStatus < Basilico::EventHandler
6
+
7
+ include Basilico::AppHelpers
8
+
9
+ def initialize
10
+ @skype = find_running_app_by_name("Skype")
11
+ end
12
+
13
+ def start(options={})
14
+ return unless running?
15
+ set_status "dnd"
16
+ set_status_message "in a Pomodoro"
17
+ end
18
+
19
+ def end(options={})
20
+ return unless running?
21
+ set_status "online"
22
+ set_status_message ""
23
+ end
24
+ alias_method :reset, :end
25
+
26
+ private
27
+
28
+ def running?
29
+ !!@skype
30
+ end
31
+
32
+ def set_status(status)
33
+ @skype.sendCommand("set userstatus #{status}", scriptName: "basilico")
34
+ end
35
+
36
+ def set_status_message(message)
37
+ @skype.sendCommand("set profile mood_text #{message}", scriptName: "basilico")
38
+ end
39
+
40
+ end
41
+ end
42
+ end
data/lib/basilico.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'basilico/event_handler.rb'
2
+
3
+ module Basilico
4
+
5
+ extend self
6
+
7
+ EVENTS = %w{start interrupt interrupt_over reset resume end break_end every}
8
+
9
+ def handlers
10
+ @event_handlers ||= []
11
+ end
12
+
13
+ def add_handler(klass)
14
+ handlers << klass
15
+ end
16
+
17
+ def run_all(event, *vars)
18
+ options = parse_variables(vars.flatten)
19
+ handlers.each do |handler|
20
+ next unless handler.handles?(event)
21
+ handler.new.send(event, options)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def self.parse_variables(vars)
28
+ vars.inject({}) do |hash, pair|
29
+ key, value = pair.split("=")
30
+ value = value.to_i if value =~ /\A\d+\Z/ and key != "title"
31
+ hash[key] = value
32
+ hash
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ # Load all handlers
39
+ Dir[File.join(File.dirname(__FILE__), "..", "event_handlers", "*.rb")].each do |handler|
40
+ require(handler)
41
+ end
@@ -0,0 +1,28 @@
1
+ framework 'Foundation'
2
+ framework 'ScriptingBridge'
3
+
4
+ module Basilico
5
+ module AppHelpers
6
+
7
+ private
8
+
9
+ def app(bundle_id)
10
+ SBApplication.applicationWithBundleIdentifier(bundle_id)
11
+ end
12
+
13
+ def sys_events
14
+ @_sys_events ||= app("com.apple.SystemEvents")
15
+ end
16
+
17
+ def find_process(name)
18
+ sys_events.processes.detect {|p| p.name == name}
19
+ end
20
+
21
+ def find_running_app_by_name(name)
22
+ if process = find_process(name)
23
+ app(process.bundleIdentifier)
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ module Basilico
2
+ class EventHandler
3
+
4
+ def self.inherited(subclass)
5
+ Basilico.add_handler(subclass)
6
+ end
7
+
8
+ def self.handles?(event)
9
+ handled_events = instance_methods(false).map(&:to_s) & Basilico::EVENTS
10
+ handled_events.include?(event)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Basilico
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: basilico
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Laszlo Bacsi
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-02 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Basilico is a framework for handling Pomodoro events while also providing useful events out of the box
23
+ email: lackac@lackac.hu
24
+ executables:
25
+ - basilico
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - bin/basilico
32
+ - lib/basilico/app_helpers.rb
33
+ - lib/basilico/event_handler.rb
34
+ - lib/basilico/version.rb
35
+ - lib/basilico.rb
36
+ - event_handlers/adium_status.rb
37
+ - event_handlers/ichat_status.rb
38
+ - event_handlers/log_events.rb
39
+ - event_handlers/skype_status.rb
40
+ - README.md
41
+ has_rdoc: true
42
+ homepage: http://github.com/lackac/basilico
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 23
65
+ segments:
66
+ - 1
67
+ - 3
68
+ - 6
69
+ version: 1.3.6
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.7
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Basilico is an event handling framework for the Mac OS X Pomodoro application
77
+ test_files: []
78
+