Specifying Coordinates for Selection in Acorn
April 23, 2011

I ran into an issue this morning that didn’t allow me to select a box of a certain size (say, 320x480 like all iPhone devs want to do) in Acorn without going and doing some pretty crazy workarounds. There’s no clear solution to this issue but I wrote a script that does it the simplest way. It’s a commandline program that will create the box in the active document of your choosing. Unfortunately you will have to go into your terminal to run it, but in most cases I have a terminal open and at the ready so this is the best solution for me!

Without further adieu, here’s the script:

#!/usr/bin/ruby

document = 1
if ARGV.length == 2 then
  x = ARGV[0].to_i
  y = ARGV[1].to_i
elsif ARGV.length == 3 then
  document = ARGV[0].to_i
  x = ARGV[1].to_i
  y = ARGV[2].to_i
else
  puts 'usage: acorn_select (document_num x y) || (x y)'
end

# now we are going to build the osascript command

script = "osascript -e \"tell application \\\"Acorn\\\"\"" 
script << " -e \"tell document #{document}\"" 
script <<	" -e \"select all\"" 
script <<	" -e \"delay 1\"" 
script <<	" -e \"deselect\""
script <<	" -e \"select rect {0, 0, #{x}, #{y}}\"" 
script <<	" -e \"end tell\"" 
script <<	" -e \"end tell\""

system(script)

I have this file in /usr/local/bin/acorn_select of which I run like this:

acorn_select 320 480

Or alternatively choose a document:

acorn_select 2 320 480

I’m aware that arguments can easily be passed to a separate script (which could be executed using osascript) but I don’t mind that the structure is quite rigid since it combines both scripts into one file. It appears this feature will be added soon into Acorn 3. It’s on sale until April 30th so go buy it!

<<  Back