The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniGraffle General (http://forums.omnigroup.com/forumdisplay.php?f=10)
-   -   Toggling (cycling) the color of text nodes (http://forums.omnigroup.com/showthread.php?t=20290)

RobTrew 2011-02-28 04:19 AM

Toggling (cycling) the color of text nodes
 
The nodes in my diagrams tend to be either gray, black, or red text.

By assigning this script to a keystroke with something like Keyboard Maestro or FastScripts, I can select a shape, and toggle the color of its text between black, gray, red.

[CODE]property plstBlack : {0, 0, 0}
property plstGray : {32767, 32767, 32767}
property plstRed : {65534, 0, 0}

tell application id "com.omnigroup.OmniGrafflePro"
try
set lstSeln to selection of front window
on error
return
end try
if lstSeln = {} then return

tell (first item of lstSeln)
if its text ≠ "" then
tell its text
set lstColor to its color

if lstColor = plstGray then
set its color to plstRed
else if lstColor = plstBlack then
set its color to plstGray
else
set its color to plstBlack
end if
end tell
end if
end tell
end tell[/CODE]

[COLOR="White"]--[/COLOR]

RobTrew 2011-02-28 11:13 AM

Or, to toggle the text color of all selected shapes together, something like:

[CODE]property plstBlack : {0, 0, 0}
property plstGray : {32767, 32767, 32767}
property plstRed : {65534, 0, 0}

tell application id "com.omnigroup.OmniGrafflePro"
try
set lstSeln to selection of front window
on error
return
end try
set lngSelns to count of lstSeln
if lngSelns < 1 then return

-- FIND THE FIRST SHAPE IN THE SELECTION WHICH HAS TEXT (IGNORE LINES)
set blnFound to false
repeat with oSeln in lstSeln
if (class of oSeln = shape) and (text of oSeln ≠ "") then
set blnFound to true
exit repeat
end if
end repeat

if blnFound then
-- GET THE NEXT COLOR IN THE SEQUENCE
tell (text of oSeln)
set lstColor to its color
if lstColor = plstGray then
set lstNewColor to plstRed
else if lstColor = plstBlack then
set lstNewColor to plstGray
else
set lstNewColor to plstBlack
end if
end tell

-- AND APPLY THE NEW COLOR TO ALL SELECTED SHAPES
repeat with oSeln in lstSeln
if (class of oSeln = shape) and (text of oSeln ≠ "") then set color of text of oSeln to lstNewColor
end repeat
end if
end tell
[/CODE]

RobTrew 2011-03-01 01:40 PM

Amended both examples above to allow for shapes which contain no text.

(Thanks to Whpalmer4 for spotting that issue).


All times are GMT -8. The time now is 11:03 PM.

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