Permalink
Browse files

2007-05-11 Justin Palmer <encytemedia@gmail.com>

  * sample/Photoshop/new_doc.rb,
    sample/Photoshop/new_doc_with_text.rb:
  New sample code.

2007-05-11  Laurent Sansonetti  <lsansonetti@apple.com>

  * tests/tc_ical.rb:
  Better test.

  * tests/tc_omnigraffle.rb:
  Make sure to open a document before doing the create shape test.

  * tests/as.rb:
  Rewrote to not depend on RubyCocoa anymore but use osascript(1) instead.
 
  * AUTHORS:
  Added Justin.

  * src/rbosa.c:
  Set a 'subj' attribute to the apple event if there is no direct parameter.


git-svn-id: http://rubyosa.rubyforge.org/svn/trunk@207 0d7f026f-1217-0410-b43a-e108cceea134
  • Loading branch information...
1 parent df4acfb commit 49f60acbd57eb6283f1757ca3e9b2c0c4bf39b1d @lrz lrz committed Apr 11, 2007
Showing with 110 additions and 22 deletions.
  1. +1 −0 AUTHORS
  2. +21 −0 ChangeLog
  3. +13 −0 sample/Photoshop/new_doc.rb
  4. +34 −0 sample/Photoshop/new_doc_with_text.rb
  5. +11 −1 src/rbosa.c
  6. +5 −7 tests/as.rb
  7. +5 −0 tests/tc_ical.rb
  8. +20 −14 tests/tc_omnigraffle.rb
View
@@ -5,6 +5,7 @@ Contributors:
Aaron Patterson <aaron.patterson@gmail.com>
Carlos Villela <carlos.villela@gmail.com>
James MacAulay <jmacaulay@gmail.com>
+Justin Palmer <encytemedia@gmail.com>
Michael Pruett <michael@68k.org>
Michail Pishchagin <mblsha@gmail.com>
Mike Naberezny <mike@maintainable.com>
View
@@ -1,5 +1,26 @@
+2007-05-11 Justin Palmer <encytemedia@gmail.com>
+
+ * sample/Photoshop/new_doc.rb,
+ sample/Photoshop/new_doc_with_text.rb:
+ New sample code.
+
2007-05-11 Laurent Sansonetti <lsansonetti@apple.com>
+ * tests/tc_ical.rb:
+ Better test.
+
+ * tests/tc_omnigraffle.rb:
+ Make sure to open a document before doing the create shape test.
+
+ * tests/as.rb:
+ Rewrote to not depend on RubyCocoa anymore but use osascript(1) instead.
+
+ * AUTHORS:
+ Added Justin.
+
+ * src/rbosa.c:
+ Set a 'subj' attribute to the apple event if there is no direct parameter.
+
* tests/tc_rdoc.rb:
Added rdoc-osa tests.
@@ -0,0 +1,13 @@
+# Creates a new Photoshop document with a given title and size.
+
+begin require 'rubygems'; rescue LoadError; end
+require 'rbosa'
+
+app = OSA.app('Adobe Photoshop CS2')
+app.settings.ruler_units = OSA::AdobePhotoshopCS2::E440::PIXEL_UNITS
+
+app.make(OSA::AdobePhotoshopCS2::Document, nil, :with_properties => {
+ :name => 'Ruby Rocks',
+ :width => 500,
+ :height => 500
+})
@@ -0,0 +1,34 @@
+# Creates a new Photoshop document with a given title and size, and adds a text
+# layer on it.
+
+begin require 'rubygems'; rescue LoadError; end
+require 'rbosa'
+
+app = OSA.app('Adobe Photoshop CS2')
+app.settings.ruler_units = OSA::AdobePhotoshopCS2::E440::PIXEL_UNITS
+app.instance_eval do
+ def create_document(options = {})
+ make(OSA::AdobePhotoshopCS2::Document, nil, :with_properties => {
+ :name => 'Ruby Rocks',
+ :width => 500,
+ :height => 500
+ }.merge(options))
+ end
+
+ def add_layer(name, kind)
+ kinds = %w(NORMAL GRADIENTFILL PATTERNFILL TEXT SOLIDFILL)
+ do_javascript %(
+ var doc = app.activeDocument;
+ var layer = doc.artLayers.add();
+ layer.name = "#{name || ''}";
+ layer.kind = LayerKind.#{kinds.detect {|k| k.downcase == kind} || 'NORMAL'};
+ )
+ current_document.art_layers[0]
+ end
+end
+
+app.create_document(:name => 'Schweet')
+layer = app.add_layer('A text layer', 'text')
+texto = layer.text_object
+texto.size = 40
+texto.contents = "This is some text"
View
@@ -271,6 +271,7 @@ rbosa_app_send_event (VALUE self, VALUE event_class, VALUE event_id, VALUE param
VALUE rb_timeout;
SInt32 timeout;
VALUE rb_reply;
+ unsigned has_direct_param;
error = AECreateAppleEvent (RVAL2FOURCHAR (event_class),
RVAL2FOURCHAR (event_id),
@@ -282,20 +283,26 @@ rbosa_app_send_event (VALUE self, VALUE event_class, VALUE event_id, VALUE param
rb_raise (rb_eArgError, "Cannot create Apple Event '%s%s' : %s (%d)",
RVAL2CSTR (event_class), RVAL2CSTR (event_id), error_code_to_string (error), error);
+ has_direct_param = 0;
if (!NIL_P (params)) {
unsigned i;
for (i = 0; i < RARRAY (params)->len; i++) {
VALUE ary;
VALUE type;
VALUE element;
+ FourCharCode code;
ary = RARRAY (params)->ptr[i];
if (NIL_P (ary) || RARRAY (ary)->len != 2)
continue;
type = RARRAY (ary)->ptr[0];
element = RARRAY (ary)->ptr[1];
+ code = RVAL2FOURCHAR (type);
+
+ if (code == '----')
+ has_direct_param = 1;
error = AEPutParamDesc (&ae, RVAL2FOURCHAR (type), rbosa_element_aedesc (element));
if (error != noErr) {
@@ -308,7 +315,10 @@ rbosa_app_send_event (VALUE self, VALUE event_class, VALUE event_id, VALUE param
rb_timeout = rb_iv_get (mOSA, "@timeout");
timeout = NIL_P (rb_timeout) ? kAEDefaultTimeout : NUM2INT (rb_timeout);
-
+
+ if (has_direct_param == 0)
+ AEPutAttributePtr (&ae, 'subj', typeNull, NULL, 0);
+
error = AESend (&ae, &reply, (RVAL2CBOOL(need_retval) ? kAEWaitReply : kAENoReply) | kAECanInteract | kAECanSwitchLayer,
kAENormalPriority, timeout, NULL, NULL);
View
@@ -1,11 +1,9 @@
-require 'osx/foundation'
module AS
def self.do_as(str)
- as = OSX::NSAppleScript.alloc.initWithSource(str)
- ok = as.compileAndReturnError(nil)
- raise "error when compiling '#{str}'" unless ok
- desc = as.executeAndReturnError(nil)
- raise "error when executing '#{str}'" unless desc
- desc.stringValue.to_s
+ File.open('/tmp/foo.as', 'w') { |f| f.puts(str) }
+ result = `osascript /tmp/foo.as`.chomp
+ File.unlink('/tmp/foo.as')
+ raise "error when executing osascript for '#{str}'" unless $?.success?
+ result
end
end
View
@@ -26,6 +26,7 @@
require 'test/unit'
require 'rbosa'
+require 'as'
class TC_iCal < Test::Unit::TestCase
def setup
@@ -39,6 +40,10 @@ def test_calendar_names
assert_equal(cal.name, names[i])
end
assert_equal(@ical.calendars.length, names.length)
+ assert_equal(do_as('get name of calendars'), names.join(', '))
end
+ def do_as(str)
+ AS.do_as("tell application \"iCal\"\n#{str}\nend tell")
+ end
end
View
@@ -45,20 +45,26 @@ def test_smart_get
end
def test_create_shape
- origin, size = [87.0, 68.0], [102.0, 102.0]
- g = @omnigraffle.make(OSA::OmniGraffleProfessional::Shape,
- :at => @omnigraffle.windows[0].canvas.graphics[0],
- :with_properties => {:origin => origin, :size => size})
- assert_kind_of(OSA::OmniGraffleProfessional::Graphic, g)
-
- assert_kind_of(OSA::OmniGraffleProfessional::Point, g.origin)
- assert_equal(origin[0], g.origin.x)
- assert_equal(origin[1], g.origin.y)
- assert_equal(origin, g.origin.get)
+ begin
+ @omnigraffle.open(File.join(Dir.pwd, 'data/test.graffle'))
- assert_kind_of(OSA::OmniGraffleProfessional::Point, g.size)
- assert_equal(size[0], g.size.x)
- assert_equal(size[1], g.size.y)
- assert_equal(size, g.size.get)
+ origin, size = [87.0, 68.0], [102.0, 102.0]
+ g = @omnigraffle.make(OSA::OmniGraffleProfessional::Shape,
+ :at => @omnigraffle.windows[0].canvas.graphics[0],
+ :with_properties => {:origin => origin, :size => size})
+ assert_kind_of(OSA::OmniGraffleProfessional::Graphic, g)
+
+ assert_kind_of(OSA::OmniGraffleProfessional::Point, g.origin)
+ assert_equal(origin[0], g.origin.x)
+ assert_equal(origin[1], g.origin.y)
+ assert_equal(origin, g.origin.get)
+
+ assert_kind_of(OSA::OmniGraffleProfessional::Point, g.size)
+ assert_equal(size[0], g.size.x)
+ assert_equal(size[1], g.size.y)
+ assert_equal(size, g.size.get)
+ ensure
+ @omnigraffle.documents.each { |d| d.close }
+ end
end
end

0 comments on commit 49f60ac

Please sign in to comment.