The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   AppleScripting Omni Apps (http://forums.omnigroup.com/forumdisplay.php?f=46)
-   -   Color & Applescript (http://forums.omnigroup.com/showthread.php?t=22902)

kparsons 2011-12-15 12:58 PM

Color & Applescript
 
I'm not sure if this can be done because I know [U]nothing[/U] about applescript. Basically what I want to do is be able to change the text color with a keyboard short cut key, and then turn it off by pressing (ideally the same) keyboard keys. In other words, I want to be able to change text color the same way I would a change text to bold.

All I know is that I could create a [URL="http://www.keyboardmaestro.com/main/"]keyboardmaestro[/URL] (its how I currently deal with annoying underline feature in OO) shortcut to activate a script but I don't know if applescript can change the color of text in OO.

Of course, I am not asking anyone to write a script. What I am asking if something like this is conceivably possible - I would love to be able to quickly color code certain notes, terms, etc.

whpalmer4 2011-12-15 01:41 PM

I know you can change it for an entire cell. An example:

[code]
tell application "OmniOutliner"
tell front document
set color of text of topic cell of selected rows to {0, 0, 65535}
end tell
end tell
[/code]

This code changes the contents of the topic column for the selected rows to be bright blue. I don't know how you can grab just the portion of the cell that is selected, however. What does your underlining setup look like?

kparsons 2011-12-15 03:18 PM

My underlining setup? Do you mean how I color code stuff? I use omnioutliner to outline court cases/statutes and I use certain colors to signify certain types of reasoning, etc. For example, if policy argument: blue text; if textual interpretation: orange text, etc.

Right now I just apply the colors manually, which doesn't take that long but it would be great to shave some time off of the process and be less of a disruption. I tried to just make a macro using KM and record the mouse clicks but that doesn't work well because it depends on where the program is on the screen, etc.

I could just limit a certain type of reasoning to one cell (sometimes when I copying a quote, there is multiple types of reasoning in one sentence) and then use the script you provided (and use a keyboard shortcut using KM). I was thinking maybe they was an applescript that said "turn current selection to color x".

whpalmer4 2011-12-15 03:54 PM

[QUOTE=kparsons;105182]My underlining setup? Do you mean how I color code stuff?
[/quote]
No, I meant your underlining stuff — you said you use Keyboard Maestro to "deal with annoying underline feature in OO" and I'm curious how you are doing it (haven't used Keyboard Maestro before). It might be possible to adapt what is done there (I assume that you can underline just the selected text).

[quote]
I could just limit a certain type of reasoning to one cell (sometimes when I copying a quote, there is multiple types of reasoning in one sentence) and then use the script you provided (and use a keyboard shortcut using KM). I was thinking maybe they was an applescript that said "turn current selection to color x".[/QUOTE]
Not that I found, but I don't do much tinkering with text formatting in AppleScript. My pal RobTrew is probably laughing too hard at my answer to give you a better one :-)

kparsons 2011-12-15 06:07 PM

1 Attachment(s)
Ha, sorry, what I have KM do is press control+U three times when I press control+y. KM is a macro utility (that is surprisingly powerful). I attached a screenshot which I think makes it pretty self-explanatory. I also use KM to create templates but all that is easy because it just uses keyboard input but there is no way, that I know of, to change color just using the keyboard.

kparsons 2011-12-15 06:25 PM

From what I have read, and the little bit of it I understood, I would need a way for applescript to identify the selected text. I found [URL="http://macscripter.net/viewtopic.php?id=20860"]this[/URL] discussion of it on macscripter. Honestly, I don't understand applescript but I do have book on the way about - I've got it in my head that I am going to figure out a way to do this.

whpalmer4 2011-12-15 07:24 PM

Do you have OmniOutliner or OmniOutliner Pro? Pro has a feature called Named styles that allows you to select some text and press a function key to instantly apply that style. You could have up to 8 of them (F1-F8), and the style could of course be as simple as just changing the text color. See the built-in help for "Named styles" for more details. Plain old OmniOutliner can view and edit named styles, but can't create new ones, and they don't appear to get the function key binding, so it wouldn't be so useful. If you're a student, the educational upgrade price to Pro is only $25, and if you're a practicing attorney I don't want to hear any complaining about the price or I'll need to collect a hefty retainer before answering any more questions from you :-)

RobTrew 2011-12-15 11:08 PM

1 Attachment(s)
whpalmer4 will correct me if I am missing something here, but I think the key problem is that the Applescript library doesn't offer us a reference to selected text (only to selected rows), so there doesn't seem to be anything very quick or elegant in sight.

[QUOTE=kparsons;105182]I tried to just make a macro using KM and record the mouse clicks but that doesn't work well because it depends on where the program is on the screen[/QUOTE]

A workaround might be to get KM5 to open the color dialog, and then get Applescript to position and size the dialog (at top left of the screen) so that mouse click coordinates relative to the top left corner of the display can be used.

You could use a fragment of Applescript like:
[CODE]tell application id "OOut"
activate
set strAppName to name
end tell

tell application id "sevs"
tell window "Colors" of application process strAppName
set position to {0, 22}
set size to {300, 400}
end tell
end tell[/CODE]

inside a KM5 macro like the one attached below, which specifies a color in terms of RGB values. Not fast, a bit klunky, but seems to work on my system :-)

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

RobTrew 2011-12-15 11:13 PM

1 Attachment(s)
PS

A faster approach might be to create a few KM macros which use a similar technique (positioning and sizing the color dialog at top left of the screen), to click on one of the user-defined colors at the bottom of the dialog.

(one way of reading off the screen coordinates is to use the Cmd-Shift-4 screen capture cursor).

(Sample macros for user colors 1-6 below)

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

kparsons 2011-12-16 08:46 AM

Thank you guys for your help. The named styles option actually works really well. What I will do is create a KM where when, for example, I press ctrl+shift+(x) it will trigger one of the function keys (because it is physically awkward to use function keys when typing).

Robtrew, I got your macros to work to on my system, but as you said its a clunky. Its too bad there isn't a uniform applescript library for all programs on a mac.


All times are GMT -8. The time now is 04:04 AM.

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