|
Which version
of FreeHand should I use
(or: FreeHand crashes when
I try to copy and paste, what am I doing wrong?)
For scripting purposes I recommend upgrading
to FreeHand 9 because there's a bug in FreeHand 7 and 8 that
crashes FreeHand when you try to paste an item from the clipboard.
The workaround is to import the item from a separately saved file.
It works fine then.
What
do I do to access commands that are not scriptable?
The first problem you are faced with
when scripting FH, is that there are only very few commands available
in the dictionary. To circumvent this, you should install either PreFab
Player, or (if you don't want to burden your system folder with
any extra extensions) Sändi's Additions, both available via
bbs.applescript.net
(look in the top pulldown menu).
Those AppleScript additions provide
you with the ability to send keyboard combinations to FreeHand, effectively
giving you access to most commands.
A lot of important commands are not
accessible through AppleScript, like editing the contents of a text
box. The workaround for this is to have a Scripting Addition like
Sändi's or Sigma's, and assign simple shortcuts. I recommend
that a shortcut should only consist of command and a non-modifier
key, because I had bad experiences with more complex shortcuts like
Command+Option+2.
How do I edit the content
of text boxes?
First, any object you want to edit through
AppleScript, should have a name. You can apply a name to an object
with the Set Note panel (Windows -> Xtras -> Set Note).
Activate the object (in this case, your text box), type in the name
in the Set Note panel, and hit the enter key. Now, you can easily
access it through AppleScript with the itsName attribute, as
in:
tell application "FreeHand"
activate
select itsName "my text box"
And that's also our first step to changing the contents of a text
box. The next thing we have to do, is to call the Text Editor window
and select all existing text, using Sändi's Addition:
TypeText "e" with command and shift
TypeText "a" with command
I assumed the shortcut Command+Shift+E for the text editor.
Please make sure you have a shortcut for invoking the text editor,
and that you are typing the correct shortcut in AppleScript. Also
make sure, that FreeHand is the frontmost application (note the activate
command above), otherwise the shortcut won't work. Now, the text editor
is open, all text is selected, and all you have to do, is to type
in the new text (overwriting the original text):
Now, the text editor is open, and all
you have to do, is to type in the new text:
TypeText "Hello, World."
Instead of this literal string, you can also use a variable.
In order to confirm the changes, we need to hit the enter key. Not
just return (which would just produce a new paragraph in the text
box), it needs to be the enter key:
TypeText (ascii character 3)
ASCII 3 represents
the enter key. FreeHand should show you now the text box with the
words, "Hello, World." However, it is a very good idea to add this
last line to your script:
update
end tell
This way we can make sure that the screen is being redrawn. It is
also a good idea to refresh the screen whenever you make any changes
in FreeHand, so you have better visual control over what your script
is doing when it's running.
For the sake of completeness, here's
the whole script again (requires Sändi's addition, Command+Shift+E
as the shortcut for the text editor, and an existing text box named
"my text box" in the frontmost FH document):
tell application "FreeHand"
activate
select itsName "my text box"
TypeText "e" with command and shift
TypeText "a" with command
TypeText "Hello, World."
TypeText (ascii character 3)
update
end tell
FreeHand doesn't
respond to the commands properly, especially when I'm trying to send
FreeHand a shortcut. What am I doing wrong?
Sometimes the pace of the AppleScript
might be too much for FreeHand, so try and add a short delay at the
crucial spots in your script with the "delay" command from AppleScript's
standard additions:
delay 0.5
This pauses the script for half a second and gives FreeHand some time
to process the last command. Often enough, simply forcing FreeHand
to update regularly, will do:
tell application "FreeHand"
update
end tell
You don't need the tell command if you're already inside a FreeHand
tell block, I added it here for completeness. Another important thing
is to make sure that FreeHand is the frontmost application whenever
you are sending a keyboard shortcut:
tell application "FreeHand"
activate
end tell
You have to activate FreeHand BEFORE you send any commands
or shortcuts.
If you have any further questions
to add to the FAQs, please get in touch with Rainer Erich Scheichelbauer
at the following addresses:
Thanks!
|