I often use the change clipboard style action, but in some cases, it generates more problems than it solves, for example in Evernote, where it reduces line and paragraph spacing to 1.
Well spaced out technical info is compressed into one difficult to read block of text.
I am trying in vain to write a macro to Show the Font Menu (the same in all apps) , navigate to the font size and set it to 18. I even tried using UI Browser but had to stop before I had a nervous breakdown.
Sets the Size value to 18 in the open “Fonts” window of the frontmost app:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "System Events" to set frontApp to name of first process whose frontmost is true
tell application "System Events"
tell application process frontApp
tell window "Fonts"
tell splitter group 1
tell group 1
tell text field 1
set value to "18"
confirm
end tell
end tell
end tell
end tell
end tell
end tell
If you are always doing this in a specific app (for example TextEdit), then you can target the app directly with tell application process "TextEdit" and without the set frontApp to name of […] stuff.
Hello Tom
Thanks again for an excellent script. Just a minor point.
I found that the script sometimes worked and other times not. The solution is to first attribute an arbitrary font size (that you don't want here 10) and then attribute the font size you want (here 18).
I was wondering how I should modify the script to choose the font family instead of font size.
Your script is very nice because it preserves the paragraph formatting which is lost if you go the change via clipboard route.
thanks again
tell application "System Events"
tell application process "Evernote"
tell window "Fonts"
tell splitter group 1
tell group 1
tell text field 1
set value to "10"
confirm
set value to "18"
confirm
end tell
end tell
end tell
end tell
end tell
Ronald, yesterday I spent at least 3 hours to figure out how to do it.
I failed.
Via AppleScript UI scripting, I can select a font family (a row) from the table, but this is not enough to “activate” it. Click (or AXPress for the matter) doesn’t work, neither on the row, nor on the text field of that row, nor on the UI element. Confirm doesn’t help.
Disclaimer: It is quite possible that I am missing the obvious (as it seems to happen to me frequently recently).
Hello Tom, sorry for the delay. Thank you so much for all the time you spent on this issue. I am embarrassed to have taken so much of your time and effort. I thought that it would be just a question on column 2 instead of column 1.
I did not find anything, but will continue to search and give you an update.
thanks again VERY much !
Don’t worry, I’m doing it also because I’m a very curious person and want to find out how/if it can be done, even if I know that I never will use the resulting script/macro
I found this very interesting discussion and surprising solution in the Evernote forum and the solution below.
In order for this solution to work, both the font name and the font size must be listed in the document.
It works perfectly for font size. For font name however, it works only for certain fonts, and even when it does it works intermittently: sometimes yes, sometimes no.
Once again, thanks very much for giving this problem some thought.