Jump to content

Workflow/Shortcut to clear clipboard


Recommended Posts

Hi everyone, is there a way to clear the clipboard history without actually having to type "clear" inside alfred everytime. Thinking of having a shortcut or button on the touchbar to just tap and clear the clipboard history? Any API/Applescript or something else I can do to accomplish this?

 

thanks

Link to comment
Posted (edited)
17 hours ago, andy4222 said:

Any API/Applescript or something else I can do to accomplish this?

 

The following snippets will clear the current clipboard:

 

In AppleScript:

use framework "AppKit"
current application's NSPasteboard's generalPasteboard's clearContents()

 

In JXA:

ObjC.import('AppKit');
$.NSPasteboard.generalPasteboard.clearContents;

 

Alfred doesn't have an API method to clear its clipboard history, but you can use the following scripts to tell Alfred to search for "clear", then simulate ↩:

 

In AppleScript:

tell application id "com.runningwithcrayons.Alfred" to search "clear"
tell application "System Events" to key code 36

 

In JXA:

Application('com.runningwithcrayons.Alfred').search('clear');
Application('System Events').keyCode(36);

 

Edited by deanishe
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...