VectorWorks is a CAD application with limited AppleScript support. It has it’s own scripting language, VectorScript, based on Pascal. The language is quite powerful and indeed beloved by many VectorWorks users. Through the AppleScript DoScript command it is possible to run a VectorScript code.
I think this little script might be of use to fellow VectorScripters.
I suggest you to keep it in your Library Scripts Folder, in order to have full access to it.
I use it for testing on the fly script snippets from online lists. If you are reading this, I guess you might also have this habit.
Copy a valid VectorScript snippet, for example this simple line:
alrtDialog(‘Hey! I was called by AppleScript!’);
Then run the following:
-- Orso.b.schmid 2006 -- run a VectorScript from the clipboard tell application "VectorWorks" activate try -- extract clean text from the clipboard DoScript («class ktxt» of ((the clipboard as string) as record)) on error errorMessage display dialog errorMessage -- something went wrong with string coercion end try end tell
If your clipboard content wasn’t a valid string, you get an AppleScript error.
If your script snippet wasn’t a valid VectorScript, you get a VectorWorks error.
The main point is to clean the clipboard text from it’s style attributes. The VectorScript compiler sends an error, if the text is styled. This is done thru the record conversion, then picking only the needed portion of text string, dropping it’s styles.
If you want to experiment a little, try copying a string somewhere in your browser window, then run this:
set text item delimiters to return display dialog clipboard info as text set text item delimiters to ""
Do you have a “Styled Clipboard Text” somewhere?
I bet you do.
Now try this:
set text item delimiters to return -- now we overwrite the clipboard with it's own data as string set the clipboard to the clipboard as string display dialog clipboard info as text set text item delimiters to ""
Do you have a “Styled Clipboard Text” still there?
Now we try passing the clipboard data to a var, this should settle the matter, you think?
set text item delimiters to return -- now we set the clipboard to string set theClip to the clipboard as string set the clipboard to theClip as string as text as list as text as list as record -- really trying hard display dialog (clipboard info) as text set text item delimiters to ""
This is kind of unexpected, but the styles are still there: they survived all coercions.
Turning the data into a record allows extracting the clean text out of it. It’s the «class ksty», hyding hideously everywhere.
Mostly it’s a great feature of AppleScript, not loosing styles even across variables.
In this case it’s a pain.
Orso B. Schmid
Model: PoweBook g4, 1500
Browser: Safari 312.6
Operating System: Mac OS X (10.3.9)