The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniGraffle > OmniGraffle General
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
How to center text in applescript Thread Tools Search this Thread Display Modes
These work fine:

set size of self to 9
set text placement of self to top


Why doesn't this work?????:

set alignment of self to center

There aren't words for how frustrated I am right now.
 
Hi,

From what I've seen, the text alignment property is a property of the container, not the text itself. This sample code creates a rectangle with centered text inside:

tell document myDocumentName of application "OmniGraffle Professional 4"

make new shape at end of graphics of first canvas with properties {origin:{10, 10}, size:{200, 200}, draws shadow:false, draws stroke:true, name:"Rectangle", fill color:{65535, 65535, 65535}, text:{font:"Arial", size:10, alignment:center, text:"Hello!"}}
end tell

Hope this helps,

Ken
 
Hi Ken,
Thanks for the help.
I know how to create a new shape with centered text. What I am trying to do, however, is center the text of an already existing shape.
TIA,
Evan
 
Over here:

Code:
set text of g to { text: "My new text", size: 8, font: "arial", alignment: center, color:{65535,65535,65535}}

Last edited by nvahalik; 2012-04-13 at 08:09 AM.. Reason: Added URL
 
Quote:
Originally Posted by efuchs View Post
I know how to create a new shape with centered text. What I am trying to do, however, is center the text of an already existing shape.
The code needed for a Runs a script action in the Action inspector might look like this (which, crucially uses a reference to the text, to avoid coercing it to a simple string).

Code:
set refText to a reference to text of self
set alignment of first attribute run of refText to center
tell front window to set zoom to zoom * 0.999
The (possibly puzzling) zoom line at the end is a work-around to cope with a bug in OmniGraffle: scripted format changes can not be seen at the zoom level at which they were made, so a slight zoom shift is needed to see what has really happened.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting text from AppleScript ptorngaard OmniFocus Extras 0 2010-03-12 03:27 AM
Center Text in Bubbles ilevy OmniGraffle General 3 2008-09-23 12:17 PM
applescript: text snippets steve OmniOutliner 3 for Mac 2 2006-05-19 10:10 AM


All times are GMT -8. The time now is 12:09 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.