Bhishan Posted December 19, 2018 Posted December 19, 2018 (edited) There are some ways to create and use the snippets in Alfred. 1. Using snip command . We can only see the command name, and copy the snippets but cant see the contents. 2. Using clipboard manager we can search and see the contents of snippets and copy it, but can not see the preview (eg. using shift key) Here, I would like to get help creating a workflow which will write the snippets to a file and quickview it. idea: command: qsnip hello effect: copies the snippet called hello and paste the contents "hello world" to a file called "mysnip.txt" in the directory of workflow. effect: qlmanage -p mysnip.txt Problem: I am unware how to save the snippet to the file "mysnip.txt" I have shared the minimal workflow here: https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/qsnip.alfredworkflow?raw=true Edited December 20, 2018 by Bhishan
deanishe Posted December 19, 2018 Posted December 19, 2018 19 hours ago, Bhishan said: I am unware how to save the snippet to the file "mysnip.txt" Start by extracting them from the snippets.alfdb (SQLite3) file they're stored in. I'm not sure I'd bother saving them to a file and using Quick Look. It's Alfred's Large Type no good?
Bhishan Posted December 20, 2018 Author Posted December 20, 2018 @deanishe Yes, Alfred's Large Type works fine. But, how to pipe the outputs of "snip hello" to the Large Type ?
vitor Posted December 20, 2018 Posted December 20, 2018 42 minutes ago, Bhishan said: @deanishe Yes, Alfred's Large Type works fine. But, how to pipe the outputs of "snip hello" to the Large Type ? Press ⌘L on any snippet result.
Bhishan Posted December 20, 2018 Author Posted December 20, 2018 (edited) @vitor Thanks a lot. However, I also created workflow using python, following the idea of @deanishe. import sys import sqlite3 import os db= r"/Users/USERNAME/Library/Application Support/Alfred 3/Databases/snippets.alfdb" conn = sqlite3.connect(db) q = "SELECT snippet FROM snippets WHERE keyword='{} '".format(sys.argv[1]) c = conn.cursor() c.execute(q) ans = c.fetchone()[0] with open('snips.txt','w') as fo: fo.write(ans) os.system('qlmanage -p snips.txt') Edited December 20, 2018 by Bhishan
deanishe Posted December 20, 2018 Posted December 20, 2018 Just a couple of Python tips: It's a good idea to use os.expanduser('~/Library/path/to/something'). Then it Just Works for every user on every Mac. q = "SELECT snippet FROM snippets WHERE keyword='{} '".format(sys.argv[1]) Perhaps you already know this, but you should never insert user input directly into SQL. You've basically just demonstrated exactly how SQL injection security holes are made. It doesn't matter here, as the only person who can abuse it is you, and the only data you can ruin or delete are your own, but generally do not ever do this.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now