Jump to content
alfred_user

Can you invoke an Alfred function (by keyword) automatically in a workflow?

Recommended Posts

I have a workflow that has one "Terminal Command" action which invokes a bash script (I tried using the "Run Script" action but couldn't get that working, but that's a separate issue). 

 

After the bash script runs I want both my Alfred clipboard history and macOS pasteboard to be cleared (the Alfred "Clear Clipboard History" function does both in one step).

 

Perhaps clearing them could be accomplished in another way? Do you know where the Alfred clipboard history is stored?

Share this post


Link to post
12 minutes ago, alfred_user said:

Perhaps clearing them could be accomplished in another way?

 

It can, but why do you want to clear the pasteboard and history? It seems an odd thing to want a workflow to do and sounds a lot like a means to a different end.

 

So what's the end goal here?

Edited by deanishe

Share this post


Link to post

Sometimes I need to perform tasks on my work computer which are related to personal matters or other companies. These tasks could potentially involve the copying/pasting of sensitive/confidential/proprietary information like hostnames, passwords, SSH keys, etc. 

 

So I wanted to have a way to "clean up" after so no artifacts or history of these operations remain on the system. So far my script successfully clears shell/terminal history, ssh known_hosts, system logs, network connection logs, temp/cached files, etc. The last thing I want to be able to do is also clear Alfred's clipboard history. What I do now is run my workflow and then immediately after run the "Clear Clipboard History" function, which only takes a second, but it would still be cool to be able to combine it into the one workflow. 

 

Side note: As an IT leader and problem solver, I appreciate your approach to solving this problem by identifying the larger issue, so I do want to mention that: I understand that using a computer that belongs to another company introduces some privacy considerations, but I am not concerned in that regard. I've verified that performing such tasks are not in violation of any company policies and I run the IT department here so I am aware of the security and monitoring software that is employed.

 

Also, from a workflow perspective, I realize that completely wiping my system logs and shell history seems like an overkill solution to this problem, but I'm also not concerned with that. In general my typical "footprint" on company computers has been very minimal - I only install applications and store files locally that are 100% required for the tasks I need to perform, so this "clean up" workflow is a very useful and effective tool for me. 

Share this post


Link to post
3 hours ago, alfred_user said:

I realize that completely wiping my system logs and shell history seems like an overkill solution to this problem

 

It's not that it's overkill, it's that trying to clear Alfred's clipboard history programmatically is fundamentally hacky, and the best way to keep sensitive data out of your clipboard history is to not let it get in there in the first place by marking the data as "transient", so clipboard history apps ignore it. Here's Alfred's option from its Copy to Clipboard output:

pasteboard-transient.png.9c90b2f3f2306bd9c1cc1a467796314f.png

 

That's the best way to do it if it's feasible.

 

Otherwise, if you're comfortable coding, and it sounds like you are, the most reliable way is to delete the information directly from the database Alfred stores its clipboard history in. The file is located at ~/Library/Application Support/Alfred/Databases/clipboard.alfdb and it's an SQLite database. If you want to delete entries up to a certain age, the timestamps in the database use the Core Data, not UNIX, epoch so they're the number of seconds since 1/1/2001. To convert to a UNIX timestamp, add 978307200.

 

To clear the current clipboard, use the command echo -n '' | pbcopy

 

Edited by deanishe

Share this post


Link to post

@deanishe Thank you! I was able to accomplish what I was trying to do by adding this to my script, which deletes all rows from the clipboard table of that SQLite database using the sqlite3 command line tool:

 

sqlite3 ~/Library/Application\ Support/Alfred/Databases/clipboard.alfdb "DELETE FROM clipboard ;"

 

Works perfectly for my needs, but if I find that I want to preserve older clipboard history I will work on reading the Core Data timestamps in each row. Thanks again for pointing me in the right direction.

Share this post


Link to post

Also, just found that copied image files are stored in the clipboard.alfdb.data folder in the same location. If I clear out the clipboard table using the command above, it still leaves the image files in that folder, so I've modified my script to be: 

 

setopt rmstarsilent # to override the rm * verification prompt in zsh (http://zsh.sourceforge.net/Doc/Release/Options.html#index-RMSTARSILENT)
rm -f ~/Library/Application\ Support/Alfred/Databases/clipboard.alfdb.data/*
sqlite3 ~/Library/Application\ Support/Alfred/Databases/clipboard.alfdb "DELETE FROM clipboard ;"

 I delete all files from that folder before clearing the rows from the database.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...