Want to create a simple macro to empty the trash

Assistance would be appreciated to create a simple macro to empty the trash.

How's this?

(Edited. Sorry, didn't see that my Export was of a single Action and not the whole macro. But exactly the same approach as Jim.)

Empty the Trash.kmmacros (2.3 KB)

Empty Trash.kmmacros (2.1 KB)

Thanks for your help although when I change the hot key to F6 the action of emptying the trash doesn’t take place.

Empty Trash.kmmacros (2.14 KB)

Thanks for your help although when I change the hot key to F6 the action of emptying the trash doesn’t take place.

Empty Trash.kmmacros (2.14 KB)

After importing the macro, did you activate it? (in the upper righthand corner, is there a checkmark or an x?)

46 pm

I changed it to F6, and it is working here,

Empty Trash.kmmacros (2.1 KB)

A simple solution. Thanks for your assistance Jim.

1 Like

@mackinnon8467

I would suggest running it as an Applescript. I know there's already a solution, but running it as a script avoids opening up windows and hitting the keystroke (the problem is that if you change the keystroke for emptying the trash, you'll have to edit the macro again).

Empty Trash.kmmacros (1.5 KB)

Here's the script:

tell application "Finder"
   empty the trash
end tell
2 Likes

That will work, but I like to avoid use of keyboard shortcuts in Macros if I can:

image

I didn't test this, but I think you don't even need to activate Finder.

1 Like

Hey @Jim,

It’s generally a very bad idea for a macro to activate its own keyboard shortcut.

There’s too much potential for conflict.

As @JMichaelTX mentions it’s much safer to have Keyboard Maestro activate an actual menu item when possible.

-Chris

@ccstone or @JMichaelTX

On a theoretical level, in a long macro with many actions, I can see why keyboard shortcuts could fail.

On a practical level, in a two action macro, can you show what type of conflict could occur?

It is not just conflicts, it is that keyboard shortcuts can change, by either the App developer, or the user using many different tools.

It is rare for a dev to change the menus for an app (they may add menu items, but rarely rename or delete items), so it is much safer to use the KM Select Menu Action that it is to use KB shortcuts.

Ok, I don’t feel bad about my example macro. The likelihood of Apple (or a tool that the user is unaware of) changing the keyboard shortcut for emptying the trash is minimal. I doubt that my macro (in this instance) will have a conflict or failure anytime soon.

From a “best practices” perspective, I agree with you.

That said, changes to menu names could cause the same type of conflict or failure. I rarely see keyboard shortcuts or menu names change in the apps that I use. And if a macro fails after I update/upgrade software, it is a quick fix to find out what changed and then update the macro to reflect that.

I'm not sure. Another user could easily use the trash shortcut as the trigger for another KM macro.

IAC, @peternlewis has stated many times that it is unwise to use a Type a Keystroke for the same keystroke that is used to trigger the maco. He says the results are unreliable and unpredictable. So I just don't go there.

I tested it in several apps, and it worked well. @peternlewis — care to chime in? I'd like to know the details. Was I just lucky?

Yes.

Typing a keystroke that is the hot key trigger for an active macro has unpredictable behaviour, it may type the keystroke or trigger the macro, and which will vary depending on unpredictable factors including the load on the Mac, the version of OS X or Keyboard Maestro and other factors.

Your style of macro is a typical example and the failure mode you'll see is that sometimes the macro will take longer to function than normal, because the macro is actually being triggered a bunch of times before the keystroke is typed instead of triggering the hot key.

4 Likes