From pdxmph at gmail.com Tue Feb 5 14:28:30 2008 From: pdxmph at gmail.com (Michael Hall) Date: Tue, 5 Feb 2008 11:28:30 -0800 Subject: [Rb-appscript-discuss] Scripting BBEdit: Error after successful execution of everything in the script Message-ID: <0368038D-7AAD-4104-9148-769A41F629E8@gmail.com> Hi, all, I'm Mike. I'm new here, pretty new to Ruby, less new to Applescript. I'm pretty excited about rb-appscript because I've been moving the logic of a lot of little glue Applescripts to Ruby, and rb-appscript gives me a way to handle everything in one script instead of bothering with Applescript processing whatever comes back from a "do shell script." I've got a script that's reporting an error after it executes everything successfully. I could just toss stderr into /dev/null and not worry about it, but I'd like to know what I'm doing wrong, since I suspect I'm missing some basic Rubyism it might be good to know down the line. Here's the pertinent code: bb = app("BBEdit") bb.make(:new => :document) bb.documents[1].text.set(doc) bb.documents[1].text.find("#SITENAME#", :selecting_match => true, :options => {:backwards => true}) (You can substitute ':starting_at_top' or ':wrap_around' for ':backwards,' since all three end up the same way when I run this.) The script performs everything as written, but after doing the last bit and selecting the find term, it reports this error: /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.0/lib/appscript.rb:528:in `_send_command': Bad selector: not an application (app) or container (con) based reference: 4975 (Appscript::CommandError) COMMAND: app("/Applications/ BBEdit.app").documents[1].text.find("#SITENAME#", {:selecting_match=>true, :options=>{:backwards=>true}}) from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.0/lib/appscript.rb: 627:in `method_missing' from /Users/mph/Library/Scripts/ruby_repurp.rb:49 What am I doing wrong? Thanks for any insight. -Mike -- M. Hall pdxmph at gmail.com (mail, im) http://mph.puddingbowl.org From hengist.podd at virgin.net Tue Feb 5 15:55:53 2008 From: hengist.podd at virgin.net (has) Date: Tue, 5 Feb 2008 20:55:53 +0000 Subject: [Rb-appscript-discuss] Scripting BBEdit: Error after successful execution of everything in the script In-Reply-To: <0368038D-7AAD-4104-9148-769A41F629E8@gmail.com> References: <0368038D-7AAD-4104-9148-769A41F629E8@gmail.com> Message-ID: On 5 Feb 2008, at 19:28, Michael Hall wrote: > I've got a script that's reporting an error after it executes > everything successfully. I could just toss stderr into /dev/null and > not worry about it, but I'd like to know what I'm doing wrong, since I > suspect I'm missing some basic Rubyism it might be good to know down > the line. > > Here's the pertinent code: > > bb = app("BBEdit") > > bb.make(:new => :document) bb.documents[1].text.set(doc) > > bb.documents[1].text.find("#SITENAME#", :selecting_match => > true, :options => {:backwards => true}) > > (You can substitute ':starting_at_top' or ':wrap_around' for > ':backwards,' since all three end up the same way when I run this.) > > The script performs everything as written, but after doing the last > bit and selecting the find term, it reports this error: > > /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.0/lib/appscript.rb:528:in > `_send_command': Bad selector: not an application (app) or container > (con) based reference: 4975 (Appscript::CommandError) > COMMAND: app("/Applications/ > BBEdit.app").documents[1].text.find("#SITENAME#", > {:selecting_match=>true, :options=>{:backwards=>true}}) > from /Library/Ruby/Gems/1.8/gems/rb-appscript-0.5.0/lib/appscript.rb: > 627:in `method_missing' > from /Users/mph/Library/Scripts/ruby_repurp.rb:49 It's a compatibility glitch. One of the perils of trying to black-box reverse-engineer AppleScript's inner workings is that I don't always guess exactly right the first time, although after 4+ years in the field they're getting pretty rare. The problem on this occasion is that BBEdit's 'find' command is returning a by-range reference with integers as the 'start' and 'stop' positions (e.g. 4, 13), whereas appscript expects these to be given as references (con.characters[4], con.characters[13]). I'll fix it in the next day or so and let you know when it's ready. Apologies for the inconvenience, and thanks for the heads-up, has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org From hengist.podd at virgin.net Wed Feb 6 06:43:37 2008 From: hengist.podd at virgin.net (has) Date: Wed, 6 Feb 2008 11:43:37 +0000 Subject: [Rb-appscript-discuss] Scripting BBEdit: Error after successful execution of everything in the script In-Reply-To: References: <0368038D-7AAD-4104-9148-769A41F629E8@gmail.com> Message-ID: <1DC2F16E-F7ED-4B81-B1A0-547B462AECFA@virgin.net> On 5 Feb 2008, at 20:55, has wrote: > On 5 Feb 2008, at 19:28, Michael Hall wrote: >> >> bb.documents[1].text.find("#SITENAME#", :selecting_match => >> true, :options => {:backwards => true}) >> > It's a compatibility glitch. Okay, fix is now available from svn (revision 456): svn checkout http://appscript.svn.sourceforge.net/svnroot/appscript/rb-appscript/trunk/ rb-appscript-trunk If you'd prefer a gem, drop me a note off-list and I'll email a copy off-list. HTH, and thanks again, has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org From tim at thinkglobal.net Wed Feb 20 16:21:28 2008 From: tim at thinkglobal.net (Tim Gildea) Date: Wed, 20 Feb 2008 16:21:28 -0500 Subject: [Rb-appscript-discuss] Help with types? Message-ID: <47BC99D8.9010507@thinkglobal.net> Hello, I'm having some trouble dealing with types in rb-appscript, and was hoping that someone with more experience might be able to offer some advice. I'm trying to retrieve the scaling percentage of an image in QuarkXPress 7. In AppleScript: tell application "QuarkXPress" tell document 1 scale of image 1 of picture box "picture" end tell end tell This produces {"34.8%", "27.4%"}, which is the expected result for this document. And my attempt to translate this into Ruby (in irb): >> x = quark.documents[1].picture_boxes['picture'].images[1].scale.get(:result_type => :list) => [#, #] >> x[0].data => "\027Y\000\000" >> x[1].data => "%F\000\000" What is this, and how can I decode it to a Float? Thanks, Tim Gildea -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rb-appscript-discuss/attachments/20080220/3850c39a/attachment.html From hengist.podd at virgin.net Thu Feb 21 10:04:53 2008 From: hengist.podd at virgin.net (has) Date: Thu, 21 Feb 2008 15:04:53 +0000 Subject: [Rb-appscript-discuss] Help with types? In-Reply-To: <47BC99D8.9010507@thinkglobal.net> References: <47BC99D8.9010507@thinkglobal.net> Message-ID: On 20 Feb 2008, at 21:21, Tim Gildea wrote: > I'm having some trouble dealing with types in rb-appscript, and was > hoping that someone with more experience might be able to offer some > advice. I'm trying to retrieve the scaling percentage of an image > in QuarkXPress 7. In AppleScript: > tell application "QuarkXPress" > tell document 1 > scale of image 1 of picture box "picture" > end tell > end tell > This produces {"34.8%", "27.4%"}, which is the expected result for > this document. > > And my attempt to translate this into Ruby (in irb): > >> x = > quark > .documents > [1].picture_boxes['picture'].images[1].scale.get(:result_type > => :list) > => [#, # size=4>] > >> x[0].data > => "\027Y\000\000" > >> x[1].data > => "%F\000\000" > What is this, and how can I decode it to a Float? I notice your AppleScript doesn't specify an 'as list' coercion. What happens if you don't specify a result type in the Ruby command? That's the only obvious difference between the two scripts that I can see. I don't have QXP myself but the 'FX% ' type is a custom type defined by QXP itself, presumably to represent percentage values. IIRC, QXP also provides a 'coerce' command for converting between these custom types and standard types, which might also be useful. HTH has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org