I’m using Keyboard Maestro to achieve this at the moment, but I would like to know if it’s possible to do this using AppleScript?
I’m not too familiar with AS, just the very basic things.
Here’s my Keyboard Maestro post with all the information
I’m using Keyboard Maestro to achieve this at the moment, but I would like to know if it’s possible to do this using AppleScript?
I’m not too familiar with AS, just the very basic things.
Here’s my Keyboard Maestro post with all the information
Thank you for the replies.
I’m a bit confused, though, and I’m not sure if I was able to explain what I’m experiencing. Let me try it again.
So regardless of the app I’m using at the moment, when I hit the shortcut to open the Character Viewer, I see this (never mind the tab. In this case it’s the arrows, but it could be any other tab):
So as you can see the window is not in focus, so if I start typing what I want to search (for example a specific emoji), it starts typing in the app (for example TextEdit) instead of the search field in the Character Viewer.
So when I click the window, then I get this
As you can see, the window is now in focus and whatever I type, goes in the search field, not TextEdit.
I was looking at your script, and even though I’m not knowledgeable enough, I couldn’t understand if that’s doing what I’m trying to achieve?
So for example, my Keyboard Maestro macro is this:
So what it does is, when I hit Control+CMD+Space, it pauses the macro until it finds this image on the screen:
When it does, it resumes the macro and it clicks -30px above that same image, which ends up being the top bar of the Character Viewer, making it be in focus.
This would be less predictable than the one I have now using Keyboard Maestro where, no matter where the window is, it will always find it, because it’s relying on an image, not coordinates, which could (and will definitely) change all the time.
Ok, no worries then. I will stick to Keyboard Maestro then.
Really appreciate your time and help!
I have a sample script below that will bring the Character viewer to the front in the App “TextEdit”.
tell application "TextEdit" to activate
delay 1
tell application "System Events"
set appName to short name of (process 1 whose frontmost is true)
if (name of processes) contains "CharacterPalette" then
tell process "CharacterPalette" --"Emoji & Symbols"
if exists window "Character Viewer" then
tell window "Character Viewer" to perform action "AXRaise"
delay 5
end if
end tell
end if
end tell
and here is a more complex version that will make sure the “Character Viewer” window is open.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "TextEdit" to activate
delay 0.5
tell application "System Events"
set appName to short name of (process 1 whose frontmost is true)
set flag to true
if (name of processes) contains "CharacterPalette" then
tell process "CharacterPalette"
if (count windows) > 0 then set flag to false
end tell
end if
if flag then
tell application process appName
click menu item "Emoji & Symbols" of menu "Edit" of menu bar 1
delay 1
end tell
end if
tell process "CharacterPalette" --"Emoji & Symbols"
if name of window 1 is not in {"Characters", "Character Viewer"} then
perform action "AXPress" of button 1 of UI element 1 of row 1 of table 1 of scroll area 1 of pop over 1 of window 1
delay 0.5
end if
if exists window "Characters" then
click button 2 of window "Characters"
delay 0.5
end if
if exists window "Character Viewer" then
tell window "Character Viewer" to perform action "AXRaise"
delay 3 -- this will let the window be shown as active (not needed)
end if
end tell
end tell