Is It Possible to Disable Macros Based on Last-Used-Date and Modification-Date?

Hello Folks,

Situation:

I have a Smart Group called: Citrix Mail Macros not used in the last 3 weeks.
The Smart Group Search Criteria is: gr:"#Citrix Viewer Palette" e: -used:21d -mod:21d

For those that don't use Smart Groups, this one is a collection of any enabled macros that I haven't used or modified in the last 21 days. I use this to limit my rather large Citrix palette which I use to file, search folders etc.

Every day while I'm logged on to Citrix, I have a time of day macro (11:10 am) select that Smart group, select all the containing macros and disable them using the Keyboard Maestro menu.

Now that I have explained the situation, here is my ask.

Is there a script or a way for KM to automatically Search and Disable macros using the search string criteria I identified above (without the Smart Group process that I identified)?

Basically, using a time of day trigger, disable macros in this criteria (gr:"#Citrix Viewer Palette" e: -used:21d -mod:21d)?

As usual, thanks much!

KC

Hey KC,

Something similar to this:

set usedDate to (current date) - 10 * days
set modDate to (current date) - 10 * days

tell application "Keyboard Maestro"
   set macroList to macros whose used date < usedDate and modification date < modDate and enabled = true
   
   return macroList
end tell

You may be able to:

set enabled of (macros whose used date < usedDate and modification date < modDate and enabled = true) to false

Or you may have to loop through and set each one individually.

I'm not going to test, because I don't want to cause myself any static at the moment

-Chris

1 Like

@ccstone Thank you for answering Chris. I'll try to use your code to sort this out. Much appreciated.

KC

Holler at me if you get stuck.

Chris,

You must have heard me yelling!! :slight_smile:
I'm in quick sand up to my chin. Help! My AppleScript skills from 1-10 is -3.

Thank you.
KC

Hey KC,

Read through the script. It should be fairly obvious what it's doing, but let me know if anything confuses you.

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/14 11:03
# dMod: 2021/12/14 11:03 
# Appl: Keyboard Maestro
# Task: Disable Macros Whose Last-Used-Date or Modification-Date is Over 21 Days Old.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro, @Disable, @Macros, @Used-Date, @Mod-Date, @Modification, @Date
--------------------------------------------------------

set todaysDate to current date
set time of todaysDate to 0 -- sets time to midnight

set usedDate to todaysDate - 21 * days
set modDate to todaysDate - 21 * days

# Disable
tell application "Keyboard Maestro"
   
   set enabled of ¬
      (macros whose enabled = true and (used date < usedDate or modification date < modDate)) ¬
         to false
   
   # Enable	
   # set enabled of ¬
   # 	(macros whose enabled = false and (used date < usedDate or modification date < modDate)) ¬
   # 		to true
   
end tell

--------------------------------------------------------
1 Like

Thank you Chris!

So in order to limit this to a particular macro group, should I add this line after
tell application "Keyboard Maestro" ?

set MacroList to name of every macro in macro group "#Citrix Viewer Palette"

Hey KC,

Notice the “tell macro group” line and where I've had to add: “its macros”.

tell application "Keyboard Maestro"
   
   tell macro group "Test Group.ccstone"
      
      set enabled of ¬
         (its macros whose enabled = true and (used date < usedDate or modification date < modDate)) ¬
            to false
      
      # Enable	
      # set enabled of ¬
      # 	(its macros whose enabled = false and (used date < usedDate or modification date < modDate)) ¬
      # 		to true
      
   end tell
   
end tell

-Chris

3 Likes

@ccstone -

Oh my! This looks way too promising.

I’m going to try this after I teach my Photoshop class tonight. I’ll be sure to check back.

Thanks in advance Chris!

KC

1 Like

Christopher Stone! You did it again! This is wonderful. I simply changed the or to and to accommodate both criteria, and it worked flawlessly.

It is so kind and thoughtful, of you, to use your spare time and energy to create this script for me.

I am very appreciative. Lastly, thank you for the support and dedication you provide to this forum.

KC

2 Likes