osaka 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,18 +30,13 @@ module Osaka
30
30
  def self.debug_prints?
31
31
  @@debug_info_enabled
32
32
  end
33
-
34
- def self.execute(applescript)
35
- script_commands = applescript.gsub("\"", "\\\"").split(';')
36
- escaped_commands = ""
37
- script_commands.each { |l|
38
- escaped_commands += " -e \"#{l.strip}\""
39
- }
33
+
34
+ def self.print_debug_info_for_escaped_commands(original_applescript_commands, escaped_commands)
40
35
  if (debug_prints?)
41
36
  if (@@debug_info_format == :plain_text)
42
37
  debug_output = "Executing: osascript#{escaped_commands}"
43
38
  elsif (@@debug_info_format == :short_html)
44
- debug_output = applescript
39
+ debug_output = original_applescript_commands
45
40
  debug_output += "<br>"
46
41
  elsif (@@debug_info_format == :script)
47
42
  File.open(@@debug_info_script_filename, File::WRONLY|File::APPEND|File::CREAT, 0755) { |file|
@@ -50,14 +45,9 @@ module Osaka
50
45
  end
51
46
  puts debug_output
52
47
  end
53
-
54
-
55
- output = ""
56
- begin
57
- output = do_system("osascript#{escaped_commands}")
58
- rescue Osaka:: SystemCommandFailed
59
- raise(Osaka::ScriptRunnerError, "Error received while executing: #{applescript}")
60
- end
48
+ end
49
+
50
+ def self.print_debug_info_for_additional_output(output)
61
51
  if (!output.empty? && debug_prints?)
62
52
  if (@@debug_info_format == :plain_text)
63
53
  debug_output = "Output was: #{output}"
@@ -66,6 +56,39 @@ module Osaka
66
56
  end
67
57
  puts debug_output
68
58
  end
59
+ end
60
+
61
+ def self.execute(applescript)
62
+ script_commands = applescript.gsub("\"", "\\\"").split(';')
63
+ escaped_commands = ""
64
+ script_commands.each { |l|
65
+ escaped_commands += " -e \"#{l.strip}\""
66
+ }
67
+
68
+ print_debug_info_for_escaped_commands(applescript, escaped_commands)
69
+
70
+ output = ""
71
+ begin
72
+ output = do_system("osascript#{escaped_commands}")
73
+ rescue Osaka::SystemCommandFailed => ex
74
+ if ex.message =~ /assistive devices/
75
+ puts <<-eom
76
+ Osaka execution failed with the error: #{ex.message}
77
+ The reason for this is probably that you didn't enable the acess for assistive devices.
78
+ Without this enabled, Osaka won't be able to execute applescript and thus won't work.
79
+ You can turn this on (in mountain lion) under:
80
+ system preferences -> Accessibility -> Enable access for assistive devices
81
+ If you are under snow leopard, it is under:
82
+ system preferences -> Universal Access -> Enable access for assistive devices
83
+
84
+ Osaka will not continue as it won't work without this enabled. Please enable it and re-run.
85
+ eom
86
+ exit
87
+ return
88
+ end
89
+ raise(Osaka::ScriptRunnerError, "Error received while executing: #{applescript}")
90
+ end
91
+ print_debug_info_for_additional_output(output)
69
92
  output
70
93
  end
71
94
 
@@ -75,8 +98,8 @@ module Osaka
75
98
 
76
99
  private
77
100
  def self.do_system(command)
78
- output = `#{command}`
79
- raise Osaka::SystemCommandFailed unless $?.success?
101
+ output = `#{command} 2>&1`
102
+ raise Osaka::SystemCommandFailed, "message" + output unless $?.success?
80
103
  output
81
104
  end
82
105
  end
data/lib/osaka/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Osaka
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
@@ -42,7 +42,13 @@ describe "Osaka::ScriptRunner" do
42
42
  Osaka::ScriptRunner::disable_debug_prints
43
43
  end
44
44
 
45
-
45
+ it "Should explain how to turn on the access for assistive devices when it is disabled... and exit" do
46
+ subject.should_receive(:do_system).and_raise(Osaka::SystemCommandFailed.new ("execution error: System Events got an error: Access for assistive devices is disabled. (-25211)"))
47
+ subject.should_receive(:puts).with(/system preferences/)
48
+ subject.should_receive(:exit)
49
+ subject.execute("anything")
50
+ end
51
+
46
52
  it "Should not print any debugging information by default " do
47
53
  subject.should_receive(:do_system).and_return("")
48
54
  subject.should_not_receive(:puts)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: osaka
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.4.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Bas Vodde
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-08-21 00:00:00 +08:00
13
+ date: 2012-08-22 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency