Jump to content
Bhishan

Create new snippet from clipboard content

Recommended Posts

Posted (edited)

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

 

 

 

 

clip.png

Edited by Bhishan

Share this post


Link to post
Posted (edited)

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

Share this post


Link to post

**Update**  

 

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.

Share this post


Link to post
Posted (edited)

@deanishe

I guess I got what you mean:

 

workflow:

Keyword sni ==> get argument name to "arg1" ==> Snippet and use "arg1" as trigger name.

 

I will try this method. If I could not manage to get it done, will seek further suggestion.

Edited by Bhishan

Share this post


Link to post
Posted (edited)

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

Share this post


Link to post
Posted (edited)

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.

 

 

 

 

up1.png

Edited by Bhishan

Share this post


Link to post

@deanishe  Where are the snippets stored?  May be If I create a directory "TemporarySnippets" in that folder and create a text file/json file/ whatever and call the snippet trigger afterwards?

Share this post


Link to post

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.

 

Share this post


Link to post
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.

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