@UI Toggle Show/Hide Emoji & Symbols (CharacterPalette) Window


MACRO:

@UI Toggle Show/Hide Emoji & Symbols (CharacterPalette) Window


--- VER: 2.0    2017-09-04 ---

DOWNLOAD:

@UI Toggle Show-Hide Emoji & Symbols (CharacterPalette) Window.kmmacros (18 KB)

Important Notes -- Read BEFORE You Use:
1. Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
2. Macro was uploaded with a TRIGGER, unlike most of my macros


Use Case

  • Automate show/hide of Emoji & Symbols window, position near mouse, and select default character group.

My thanks to @Tom for getting this started with his macro/script.


Example Output

Emoji & Symbols (Special Characters) Window

image


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Toggle Show/Hide of Emoji & Symbols (Special Characters) Window

HOW TO USE:

  1. Trigger this macro in the app where you want to show/hide the window
  2. Macro will SHOW the Emoji & Symbols window IF it is NOT showing;
  • The Character Group (set below) will be selected.
  • The Window will be positioned just below/right of the mouse.
  1. Macro will HIDE the Window IF it is showing.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. :wink:
      .
  • Assign a Trigger to this maro. I prefer ⌃⌘SPACE which replaces the normal hot key to show this window.
  • Move this macro to a Macro Group that is only Active when you need this Macro, probably your GLOBAL Macro Group.
  • ENABLE this Macro.
    .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    • ALL Actions that are shown in the magenta color
    • TSH__GroupName -- Default Emoji/Character Group Name
      • Set this to the Group you want initially selected
      • If the GroupName does not exist, it will be ignored.

TAGS: @UI @Window @Characters @Emoji

REQUIRES:

  1. Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
  2. El Capitan 10.11.6+
  • It make work with Yosemite, but I make no guarantees.

USE AT YOUR OWN RISK

  • While I have given this limited testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.


@Tom's AppleScript to Close Window

# AUTHOR: @Tom
# 2017-09-03

tell application "System Events"
  tell process "CharacterPalette"
    tell window "Characters"
      try
        click (first button whose description is "close button")
        # alternatively: click button 2
      end try
    end tell
  end tell
end tell

AppleScript to Show Window, Position, & Select Group

property ptyScriptName : "Move & Select Group in Emoji & Symbols Window"
property ptyScriptVer : "2.0"
property ptyScriptDate : "2017-09-04"
property ptyScriptAuthor : "JMichaelTX"

(*
-------------------------------------------------------------------------------
KM VARIABLES REQUIRED: (must be set before calling this script)
  • TSH__MousePos
  • TSH__GroupName
  
KM VARIABLES SET: (by this script)
  • <NONE>
  
REQUIRED:
  1.  macOS El Capitan 10.11.6+
      (may work on Yosemite 10.10.5, but no guarantees)
      
  2.  Mac Applications
        • Keyboard Maestro 7.3+


# Local File: /Users/Shared/Dropbox/SW/DEV/KM/Scripts/@UI @Move @Emoji & Symbols Window Below @Mouse @KM @AS.scpt
-------------------------------------------------------------------------------   
*)

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set mousePosStr to getKMVar("TSH__MousePos", ",")
set groupName to my getKMVar("TSH__GroupName", "Favorites")

set {mouseX, mouseY} to my splitStrToList(mousePosStr, ",")

set elapTime to my pauseUntilWin("Characters", "CharacterPalette", 2)

tell application "System Events"
  tell process "CharacterPalette"
    
    if ((mouseX ≠ "") and (mouseY ≠ "")) then
      --- MOVE WINDOW BELOW MOUSE ---
      tell window "Characters" to set position to {mouseX + 10, mouseY + 20}
    end if
    
    --- GET GROUP LIST ---
    set groupList to name of first UI element of rows of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Characters"
    
    set groupIndex to my getIndex(groupName, groupList)
    
    if (groupIndex ≠ 0) then
      
      --- SELECT FAVORITES GROUP ---
      select row groupIndex of table 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Characters"
      
    else
      
      --- GROUP NAME NOT FOUND ---
      set msgStr to "Emoji/Character Group NOT Found: " & groupName
      set msgTitleStr to ptyScriptName
      display notification msgStr with title msgTitleStr sound name "Basso.aiff"
      
    end if
    
  end tell
end tell

------------ END OF MAIN SCRIPT -------------------

-----------------------------------------------------------------------------------
on getKMVar(pKMVarNameStr, pDefaultValueStr) --  @KM @Get @Variable
  (*  VER: 1.0    2017-03-15
---------------------------------------------------------------------------------
  PURPOSE:  Get Value of KM Variable & Set to Default if it doesn't exist
  PARAMETERS:
    • pKMVarNameStr        | text  | Keyboard Maestro Variable Name
    • pDefaultValueStr    | text  | Default value if Variable doesn't exist
  RETURNS:  KM Var Value
  AUTHOR:  JMichaelTX
  —————————————————————————————————————————————————————————————————————————————————
*)
  local kmVarStr
  
  tell application "Keyboard Maestro Engine"
    set kmVarStr to getvariable pKMVarNameStr
  end tell
  if (kmVarStr = "") then set kmVarStr to pDefaultValueStr
  
  return kmVarStr
  
end getKMVar
----------------- END OF handler getKMVar -------------------------

-----------------------------------------------------------------------------------
on getIndex(pItem, pList) -- @List @Index
  (*  VER: 2.0    2017-08-02
---------------------------------------------------------------------------------
  PURPOSE:  Get the Index (Item #) of a Item within a List
  PARAMETERS:
    • pItem    ║ any  ║ Item to Find.  Can be text, numeric, date, or list
    • pList    ║ text  ║ List to be searched.
  RETURNS:  integer  ║ Index number (0 if NOT found) 
  AUTHOR:  JMichaelTX
—————————————————————————————————————————————————————————————————————————————————
*)
  local idx, i
  
  set idx to 0
  set lenList to length of pList
  repeat with i from 1 to lenList
    if (pItem = (contents of item i of pList)) then
      set idx to i
      exit repeat
    end if
  end repeat
  
  return idx
  
end getIndex
----------------- END OF handler getIndex -------------------------


on splitStrToList(pString, pDelim)
  
  set textDelimSave to AppleScript's text item delimiters
  set AppleScript's text item delimiters to pDelim
  
  set newList to text items of pString
  
  set AppleScript's text item delimiters to textDelimSave
  
  return newList
  
end splitStrToList

on pauseUntilWin(pWinTitle, pProcessName, pMaxTimeSec)
  local startTime, elapTime, errMsg
  
  set startTime to current application's NSDate's |date|()
  
  tell application "System Events"
    repeat until window pWinTitle of process pProcessName exists
      if ((startTime's timeIntervalSinceNow()) > pMaxTimeSec) then
        set errMsg to "Max Time of " & pMaxTimeSec & " exceeded waiting for:" & LF & ¬
          "Window: " & pWinTitle & LF & "Process: " & pProcessName
        log errMsg
        error errMsg
      end if
      delay 0.1
    end repeat
  end tell
  
  set elapTime to (-(round ((startTime's timeIntervalSinceNow()) * 100)) / 100.0)
  
  return elapTime
end pauseUntilWin
3 Likes

Wow, it’s so much to show/hide this little pop-up, requiring you to include entire functions to move/close window, string parser, etc! :stuck_out_tongue: Frustrating that Apple doesn’t make this easier.

Do you use a utility to determine that “CharacterPalette” is the process of window “Characters”? And what do you use to get the UI element names/paths?

Thanks again for the amazing work!

Yeah, I agree. Apple should have made the shortcut for it to be a toggle, like the Fonts and Color Picker windows. But they didn't. This is a very special kind of window hard to detect and manage.

UI Browser is the best tool for this.

1 Like

I know this post is from awhile ago but I came across it recently looking for a way to replicate Slack's style of inserting emoji's with a colon, followed by typing the name of the emoji. The end result looks something like this: :grimacing: but is translated to this: :grimacing:.

In my search I discovered that the latest version of MacOS (12.2 Monterey) as well as the last version (11 Big Sur) and likely others (I'm not sure when this keyboard shortcut was introduced into the OS) will show the Emoji & Symbols / Special Characters window with the keyboard shortcut: ⌃⌘space. Said another way, when you type the keyboard shortcut: ⌃⌘space on a new Mac, the Emoji & Symbols / Special Characters window will pop up.

As a simpler way (for me at least) to bring that window up, I created a very simple macro to remap :: to ⌃⌘space. This is an easier keystroke for me to remember since I'm already use to typing a single colon and then text to search for an emoji before, and many of my other text expansion macros begin with ;; followed by a text abbreviation (for example, when I type ;;opt it expands to .

Anyways, this works well for me and I thought I would share with others looking for a simple way to evoke the Emoji & Symbols or Character Viewer (whatever it's called). Just choose whatever trigger makes the most sense for you and add an action to simulate the keystroke: ⌃⌘space.

Here's a screenshot of the macro:
(Note that I have a space after the two colons to trigger the macro.)

Emoji Popup Remap Macro

And a screenshot of the window that pops up when the macro runs:
Emoji and Symbols Viewer - clean

I hope others find this helpful.

1 Like