I'm trying to create a "Service" in Automator that changes the font of the selected text in the frontmost app.
-
1The guide on How to Ask will help you refine your question by showing what you've tried and/or what exactly "you don't get". If you don't get a good answer, feel free to try editing in some details or links on what question you used and what step is failing or doesn't make sense. We love details here.– nohillside ♦Feb 27, 2013 at 18:30
-
I tried this too and have not been able to do so. I would ask Ben Waldie from automatedworkflows.com He might know. Phil– Philippe DubeFeb 28, 2013 at 3:10
2 Answers
You could assign a shortcut to a script like this:
tell application "System Events" to tell (process 1 where frontmost is true)
set {c1, c2} to value of attribute "AXSelectedTextRange" of text area 1 of scroll area 1 of window 1
end tell
tell application (path to frontmost application as text) to tell document 1
tell characters c1 thru c2
set font to "Menlo"
set size to 18
end tell
end tell
It works with TextEdit and WriteRoom, but it probably needs to be modified for other applications.
Another really awful option:
try
set old to the clipboard as record
end try
do shell script "textutil -stdin -stdout -format html -convert rtf <<< '<span style=\"font: 18px Menlo\">a</span>' | pbcopy"
tell application "System Events"
keystroke "v" using command down
keystroke "c" using {option down, command down}
keystroke "z" using command down
keystroke "v" using {option down, command down}
end tell
delay 0.05
try
set the clipboard to old
end try
After much research, the workflow below works for me in TextEdit, Mail, Notes, Stickies. Where it doesn't work is when the app uses Styles (Microsoft Word, Pages, Keynote), because the style overrides the font you input. The only way I can think to override the style is to directly script each app to make a custom style.
ApplesScript Code:
on run {input, parameters}
do shell script "pbpaste | textutil -stdin -stdout -convert rtf -font Arial -fontsize 12 | pbcopy"
tell application "System Events" to keystroke "v" using command down
return input
end run
-
1Please don't make users have to manually type the code! Always include the code in your answer so it can be directly copied and pasted! Not everyone has an app installed that can OCR a graphic image, like I just did. Apr 19, 2017 at 19:23
-
1Sorry, I wanted to show the entire workflow with the selected options in automator. Next time I will do both.– HurstonApr 23, 2017 at 14:57