Deleting Emojis From KM Macro Names – Because They Cause Sync Problems With Dropbox

Idiot that I am, I put many emojis in macro names for classification purposes, but they cause problems with dropbox not syncing my macro backups with the @DanThomas ' excellent macro repository backup method.

My objective is to first list all macros with emojis in the macro name and then delete those emojis

  1. Search for macros with emojis
    I want to create a smart group containing macros with any of the following emojis. I know which emojis I am looking for ie :bear::smirk::blossom::unamused::high_heel::blossom::thinking::heart::blush::yum::couple_with_heart::smiley_cat::person_tipping_hand::smiley_cat::bus::person_tipping_hand::rainbow::key::lady_beetle: :rabbit::bangbang::heart::heart::heart:. How would I define the smart group as any macro containing any one of those emojis, or any better any emoji in macro name

  2. Once I have my list of macros, I want to use the excellent batch search and replace macro by @cfriend which works very well (link below)

The regex I was going to use is to
search for : [ :bear::smirk::blossom::unamused::high_heel::blossom::thinking::heart::blush::yum::couple_with_heart::smiley_cat::person_tipping_hand::smiley_cat::bus::person_tipping_hand::rainbow::key::lady_beetle: :rabbit::bangbang::heart::heart::heart:]+
replace with nothing

When I run that regex on file names in Finder it works perfectly. If I run the same regex in @cfriend's macro, the emoji is deleted but macro name is either deleted of all spaces between words trimmed.

Thanks in advance for your time and help

1 Like

No idea, just passing by.
Nice weather!

Interesting quandary of yours Ronald

Can you do the opposite? Find all macros that do Not have any emojis, then disable them so you can see which ones need your attention?

1 Like

nice to hear from you. An imaginative solution which I will look at. thanks !

1 Like

Could you search by Unicode or HTML numbers? Maybe copy and paste titles into another app for the searching.

2 Likes

Thank you for the suggestion. I will do some research.

Hey @ronald,

You can use a regular expression to represent emojis. If I remember correctly there might be one on this forum, and if so I suspect that either @JMichaelTX, @ComplexPoint, @DanThomas, or I wrote it.

This pattern works in Script Debugger 8 – which uses ICU regex like Keyboard Maestro:

\p{So}+

So I suspect it will work in KM. It does – I just tested.

-Chris


Attention: This macro is strictly a demonstration of using a regular expression to search for and replace emojis.


RegEx β‡’ Search & Replace Emojis v1.00.kmmacros (8.1 KB)
Keyboard Maestro Export

2 Likes

Thanks very much for the macro!

Unfortunately it did not work. This is what I did and what happened:

KM 10.2 Catalina latest version

  • Downloaded β†’ enabled your macro
  • Changed the list of emojis to
    :bear::no_entry::magnet::hot_pepper::camera_flash::classical_building::o::rocket::white_check_mark::rose::taxi::nazar_amulet::snail::smirk::blossom::unamused::high_heel::pill::ear::hammer_and_wrench::alarm_clock::ear::ear::ear::blossom::thinking::question::exclamation::bangbang::warning::interrobang::heart::link::blush::yum::couple_with_heart::smiley_cat::person_tipping_hand::smiley_cat::bus::person_tipping_hand::rainbow::key::lady_beetle: :rabbit::bangbang::heart::heart::heart:
    as per below
  • Selected all macros in a group
  • When I run the macro, a text + emojis is displayed in a window as below and the macro names are left unchanged.

To determine if the problem is generated by my list of emojis, I downloaded your macro β†’ β†’ enabled β†’ created macros containing the same emojis you use in your macro β†’ ran your macro as is β†’ did not work as in names of the selected macros were unchanged and a text is displayed in a window as below

Thanks very much for your time and efforts to help me

Sure it did. It did exactly what it was supposed to do.

This macro was a demonstration that you could replace emojis using a regular expression – it was NOT designed to accomplish your task, and this should have been obvious to someone so experienced with Keyboard Maestro at a glance.

You're quite capable of taking my hint and building your own macro.

1 Like

OK Sorry. I will have another look.

OK now I understand. thank you

2 Likes

Hi @Ronald, going back to your original problem of wanting to remove emojis from certain Macro names.

Looking at your selected problem Macros I can see that only some of them have emojis in their names so, I would be very wary of selecting a whole bunch of Macros and applying some sort of batch renaming as you could easily mess up lots of Macros that have perfectly good names.

Instead I would suggest that you make a Macro that works on one Macro at a time. You can easily see in the Macro columns which Macros need to have their names changed as the emojis really stand out.

image

If you make a Macro that uses a hotkey it would be pretty quick to select each Macro and press the hotkey to rename it. This would also give you the chance to correct any renaming if it causes unexpected results.

The Example Macro below uses the Regex that @ccstone gave you. But in my testing I found it missed a few emojis - so, I added in an extra Magenta Action where you can add in any problematic emojis you come across.

It works by applying a series of find and replace Actions. I find this simpler than trying to do everything in one step. I'm sure others here could reduce the steps.

It first finds any emojis and replaces them with a "star" symbol. Now that all emojis are the same symbol it is easy to deal with spaces before or after them. Again, this step by step, is my approach which I find easy to understand and makes the Macro easier for editing in the future.

And to recap - this is a one Macro at a time solution. First select a single Macro in the Macro column and then run this Example Macro using whatever hotkey you have given it. If it does something strange to the name you can press ⌘Z to undo. If it fails to remove a certain emoji you can add that emoji to the Magenta Action for the next time.

EXAMPLE Remove Emojis from Macro Name.kmmacros (6.2 KB)

Click to Show Image

2 Likes

There are hundreds of macros. I don't know how I could do it one at a time. thank you very much

Hey @ronald,

You don't have to. Since Keyboard Maestro's search-replace is available to AppleScript, this problem has a relatively simple solution.

And I'm sure @ComplexPoint will chime in with a JXA solution.  :sunglasses:

-Chris


--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/10/14 15:56
# dMod: 2022/10/14 15:56 
# Appl: Keyboard Maestro, Keyboard Maestro Engine
# Task: Remove Emojies From Names of Selected Macros
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Keyboard_Maestro, @Keyboard_Maestro_Engine, @Remove, @Emojies, @Name, @Selected, @Macros
--------------------------------------------------------

tell application "Keyboard Maestro"
   set macroList to selection
   
   if length of macroList > 0 then
      if class of item 1 of macroList is macro then
         repeat with theMacro in macroList
            set macroName to name of theMacro
            set newMacroName to (my kmCng:"\\h*\\p{So}+\\h*" inStr:macroName withStr:"" usingRegEx:true usingCase:false usingTokens:false)
            set name of theMacro to newMacroName
         end repeat
      end if
   end if
   
end tell

--------------------------------------------------------
--Β» HANDLERS
--------------------------------------------------------
--Β» kmCng()
--------------------------------------------------------
--  Task: Find and Replace with RegEx using Keyboard Maestro's AppleScript search command.
--  dMod: 2019/01/19 04:33
--------------------------------------------------------
# Uses the Keyboard Maestro Engine for RegEx Support.
on kmCng:regExPat inStr:dataStr withStr:replacePat usingRegEx:regExBool usingCase:caseBool usingTokens:tokensBool
   tell application "Keyboard Maestro Engine"
      set foundDataList to search dataStr for regExPat replace replacePat Β¬
         regex regExBool case sensitive caseBool process tokens tokensBool
   end tell
end kmCng:inStr:withStr:usingRegEx:usingCase:usingTokens:
--------------------------------------------------------
2 Likes

I\ll wait to see who adds their solution written in Perl or Ack Awk

2 Likes

thanks very much. All done.

1 Like