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
ReleaseNotes
Author.@JMichaelTX
PURPOSE:
- Toggle Show/Hide of Emoji & Symbols (Special Characters) Window
HOW TO USE:
- Trigger this macro in the app where you want to show/hide the window
- 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.
- 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.
.
- 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:
- Keyboard Maestro Ver 7.3+ (don't even ask me about KM 6 support).
- 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