google docs using a shortcut to change the font color

Post your working scripts, libraries and tools for AHK v1.1 and older
partof
Posts: 110
Joined: 16 Jan 2016, 08:38

google docs using a shortcut to change the font color

13 Dec 2017, 04:00

This code doesn't keep the formatting of your text. It only copies the text of your clipboard, set a blue color to it and past it as HTML

WARNING: watch the delay, if you put a delay to short before the backspace it can break your docs (even if you chose a previous version) (It probably delete some google doc important code). Try it on a draft before...

Google script are useless for this kind of quick operation (too slow), so ahk is handy for that.

Code: Select all

; ************************************** get clipboard, change to blue color 

; ⚠ you need to download winclip (2 ahk files, save it somewhere and then change the 2 paths #Include bellow. Winclip is here: 

; https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/ 

#IfWinActive ahk_exe chrome.exe ; the shortcut will only work on chrome 
#Include C:\Users\Me\Desktop\modul_ahk\WinClip\WinClipAPI.ahk 
#Include C:\Users\Me\Desktop\modul_ahk\WinClip\WinClip.ahk

!^+p:: ; Alt(!) CTRL(^) shift(+) 
WinClip.Copy()
t := WinClip.GetText()
ClipWait

; MsgBox, % t  ; (to debug)
     ; clipboard = %t%
     ; ClipWait 
	 
var1 = <p style="color:#0000cc">
var2 = </p>
x = %var1%%t%%var2%

clipboard = %x%
ClipWait
; MsgBox, % x   ; (to debug)
     ; clipboard = %x%
     ; ClipWait 
	 
WinClip.SetHTML( x )
ClipWait
Send ^v 
;for some reason it will create a line break, to remove it:
sleep 250 ; ⚠ if no delay or too short the code will corrupt your doc!
Send {BACKSPACE}

return
#IfWinActive
For some (mysterious) reason in a larger document, it needs 2 backspaces (to remove a space + a line break)

Code: Select all

sleep 300
Send, {BACKSPACE}
sleep 300
Send, {BACKSPACE}
partof
Posts: 110
Joined: 16 Jan 2016, 08:38

Re: google docs using a shortcut to change the font color

13 Dec 2017, 06:13

edit it's much easier (and safe) to pass simply use the mouse click:

Code: Select all

; #IfWinActive ahk_exe chrome.exe ; the shortcut will only work on chrome 
; !^+p:: ; Alt(!) CTRL(^) shift(+) !^+p

; click, 652, 74 
; sleep 100
; click, 784, 180 
; return

if you want to rotate from one color to another to another: https://autohotkey.com/boards/viewtopic.php?f=6&t=41328

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 210 guests