If you do want to go the way of Quartz, I've already created a layer above it 
that you may want to use.

The gem:

https://rubygems.org/gems/AXTyper

Example Usage:

irb(main):001:0> require 'rubygems'
irb(main):002:0> require 'accessibility/string'
irb(main):003:0> include Accessibility::String
irb(main):004:0> events = keyboard_events_for "Hello, #{ENV['USER']}."
irb(main):005:0> events.each do |event| KeyCoder.post_event event end

In your case, you can try a hotkey combination like this:

irb(main):004:0> events = keyboard_events_for "\\COMMAND+\\OPTION+u"
irb(main):005:0> events.each do |event| KeyCoder.post_event event end

And there are more details in the blog post I wrote about it:

http://ferrous26.com/blog/2012/04/03/axelements-part1/



On 2012-05-02, at 9:05 AM, Joshua Ballanco wrote:

> Hmm…in general I would steer clear of scripting bridge when equivalent 
> functionality is available elsewhere. In this case, you can make use of the 
> Quartz Event Services. There's a Stack Overflow answer here that should be 
> able to get you started: 
> http://stackoverflow.com/questions/1938509/how-to-simulate-a-low-level-keypress-on-os-x
> 
> As for the exact problem you're facing, I'm not sure what the answer is. 
> Looking at the AppleScript dictionary, it seems like "command down" and 
> "option down" are special properties in the dictionary, but I don't recall at 
> the moment how to extract dictionary properties from the library. Depending 
> on where you extracted those numeric values from, there's a chance that they 
> could be different on your system (i.e. enums might change between OS 
> versions, since you're supposed to use them as enums and not numeric values).
> 
> But the short answer is: your code looks fine, and using enums/numeric 
> constants like that should work as expected in MacRuby. Have you tried the 
> equivalent code in Obj-C to see if this is specific to MacRuby?
> 
> Cheers,
> 
> Josh
> 
> 
> On Tuesday, May 1, 2012 at 11:57 PM, Josh Voigts wrote:
> 
>> Is there a way to get multiple enumerations to work, like in the
>> following example. I know I could be doing this with cocoa, but it's a
>> small scripting project. (Also I didn't feel like loading a bridge
>> support file, would that help in this case?)
>> 
>> 
>> framework 'ScriptingBridge'
>> 
>> sys = SBApplication.applicationWithBundleIdentifier("com.apple.systemevents")
>> 
>> COMMAND_KEY = 1264807268
>> OPTION_KEY = 1265594484
>> 
>> sys.keystroke("u", using: COMMAND_KEY|OPTION_KEY)
>> 
>> 
>> 
>> It seems to only recognize the first enum... I'm probably missing
>> something logically here...
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel@lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel@lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to