Jump to content

Create new snippet from clipboard content

Recommended Posts

It would be extremely useful if we can create snippets on-the-fly from the clipboard contents.


For example:

"snip tmp"   will create a snippet called "u;tmp" from the clipboard content.

So that when typing "u;tmp" will expand that snippet automatically.



For only one snippet I can do this:


Alt shift t ==> copy the clipboard to tmp.txt

u;tmpp ==> autoexpand the text after reading from tmp.txt from that workflow directory.


But, this works only for one snippet.


It would be nicer if it can be done more dynamically.


The suggestion is much appreciated.


I have provided MWE in the github shared file:

https://github.com/bhishanpdl/Shared/blob/master/Alfred_questions/aa Clipboard Copy.alfredworkflow?raw=true






Edited by Bhishan
Link to comment

Because, lets say i have a code snippet from pandas groupby in python:

gp1 = =>  daily = flights.groupby(['year','month','day'],as_index=False)


and another snippet as

gp2 = =>  daily = flights.groupby(['year','month','day'],as_index=True)


It would be easier to type u;gp1 and u;gp2  than go to clipobard manager and search for clipboard history.

Edited by Bhishan
Link to comment



I could not create Snippet triggers, but found alternative route using Alfred Keyword.


"sni hello"   will create "hello.txt" from the clipboard.

"sno hello" will read that "hello.txt" and paste to the frontmost application.


This works great, but I am only missing "u;hello" and "u;hi" etc  where I can simply type, instead of hitting keys.

Link to comment

No, that is not what I mean. I'm talking about Snippet Triggers.


You have a single snippet keyword that activates a Script Filter. The Script Filter shows you a list of the texts you've saved. You choose one and it's inserted into the current application.


Obviously, you also need to add a way to save/add texts to the workflow.

Edited by deanishe
Link to comment

I tried this:

 try to create dynamic trigger from the alfred workflow but, it did not work:


- snn hello  ==> creates hello.txt   and var:arg is set to "hello"

- tried to use that varible to make trigger object, but failed.


It creates hello.txt but u;hello  does not work.






Edited by Bhishan
Link to comment

A dynamic trigger won't work for a Snippet Trigger because the variable arg will only exist when you run the workflow via the snn keyword.


If you want any further help, please upload the workflow somewhere and post a link. Screenshots are not much use.


Link to comment
25 minutes ago, Bhishan said:

I am looking a way to create dynamic trigger using argument from the alfred workflow.


Then your workflow needs to manipulate its own info.plist or a snippet collection. Auto-generating a snippet collection is probably the simplest way.

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...