Jump to content
zsteir

Junction with modifiers

Recommended Posts

Hi all,

I've got a query to search BibDesk (based on BibQuery by Hackademic). See pic HERE. The topmost trigger "bb", can call some of the other trigger "ba" and "bt" (which I do using applescript). However, "bb", "ba", and "bt" share most of their actions. Right now, this results in a mess. But using a junction doesn't help, since it doesn't allow for modifier.

 

Is there anyway to create some sort of junction that allows for modifiers?

 

Thanks.

Edited by zsteir

Share this post


Link to post

A Junction will work if you use the mods object in your results to set modifier keys and a workflow variable, too, (e.g. action="search") and then have Filter objects before your Actions to determine whether they should run.
 
It's hard to explain in text. This demo workflow shows what I mean.
 
q8D4KLx.png

Edited by deanishe
Fix link

Share this post


Link to post

Hi Deanishe,

Sorry, but I wonder if you can help a bit more. I'm sorry for the newbie question. I am working with a python script that output an XML (using your Workflow library). It prepares a dictionary like this, where the values have been extracted previously from a text file, etc.

 

<EDIT>: after digging around a bit more, I suspect that I am using a Workflow library that is too old. I guess I need the V2 branch. I'll try to figure out how to add it...

</EDIT>

 

 _dict = {'title': title,
          'uid': _arg, 
          'valid': True, 
          'arg': _arg,
          'subtitle': sub
          }

After your previous suggestion, I found the example XML file for a script filter of this kind, which recommends using something like this:

 

<item uid="home" arg="~/" valid="NO" autocomplete="Home" type="file">
    <title>Home Folder</title>
    <icon type="fileicon">~/</icon>
    <subtitle>Home folder ~/</subtitle>
    <subtitle mod="fn">Subtext when fn is pressed</subtitle>
    <subtitle mod="ctrl">Subtext when ctrl is pressed</subtitle>
    <subtitle mod="alt">Subtext when alt is pressed</subtitle>
    <subtitle mod="cmd">Subtext when cmd is pressed</subtitle>
    <quicklookurl>https://www.alfredapp.com/</quicklookurl>
    <mod key="shift" subtitle="New subtext when shift is pressed" valid="yes" arg="shiftmod"/>
    <text type="copy">Text when copying</text>
    <text type="largetype">Text for LargeType</text>
  </item>

But I can't seem to figure out to properly add additional items to _dict.

 

When I use, for example:

 

     _dict = {'title': title,
                    'uid': _arg, 
                    'valid': True, 
                    'arg': _arg,
                    'subtitle': sub,
                    'subtitle mod=\"cmd\"' : "whatever",
                    }

I get an error "unexpected keyword argument ". It is ultimately sent to Alfred like, this, with prep_res being the array of _dict(s), I think. What generates the error is the add_item.

 

for item in prep_res:
        wf.add_item(**item)
        wf.send_feedback()

 

I'm sure I'm not constructing the dict properly, but I'm afraid I'm in over my head. The entire script is here: https://dl.dropboxusercontent.com/u/565419/bibquery.py.

 

Ideas? Many thanks.

 
Edited by zsteir

Share this post


Link to post

This can't be done using Alfred-Workflow's feedback mechanism. It doesn't currently support Alfred 3's mods.

 

Generating JSON is much easier than XML, in any case, so it's not a big problem.

 

Share this post


Link to post

You just need to create a plain, old Python dictionary and turn that into JSON with json.dump(mydict, sys.stdout).
 
It has to be the right format, of course. What's perhaps not obvious is that you can't just set arg to another dictionary. You have to set it to a JSON string: 

items = []

# First item
arg = {'alfredworkflow':{'arg':'arg goes here', 'variables':{'var1':'value1', 'var2':'value2'}}}
item = {
    'title': 'Item One',
    'arg': json.dumps(arg),
}
items.append(item)

# Other items
...
...
 
# Send to Alfred
json.dump({'items': items}, sys.stdout)

Share this post


Link to post
On 6/4/2016 at 2:00 AM, deanishe said:

It's hard to explain in text. This demo workflow shows what I mean.

I know I'm digging up an old thread, but I"m trying to follow the instructions to use mods object and filter results. The link to the demo workflow is broken. Any chance of sharing it again?

Share this post


Link to post
12 minutes ago, evanfuchs said:

I know I'm digging up an old thread, but I"m trying to follow the instructions to use mods object and filter results. The link to the demo workflow is broken. Any chance of sharing it again?

 

Sorry. Dropbox broke everything, and there's no easy way to find all the broken links. Thanks for the heads-up.

 

Here's the workflow. I've also fixed the link above.

Share this post


Link to post

Also, please bear in mind that the workflow is old. You wouldn't use the same JSON today. You don't need to smush everything into arg any more: mod can have a variables member now.

Share this post


Link to post
2 hours ago, deanishe said:

 

Sorry to hijack the thread. But I've been thinking of setting up my own service to share downloads to stuff off my own server. Can you share how you setup your workflow for it? I know your personal site is generated with Hugo and your downloads are links coming off your domain. 

Thank you.

Edited by nikivi

Share this post


Link to post
2 hours ago, nikivi said:

I know your personal site is generated with Hugo and your downloads are links coming off your domain

 

My domain and personal site are totally separate things. The former (deanishe.net) sits on a Linode and the latter (www.deanishe.net) is on GitHub Pages. I use GH Pages because it seamlessly integrates the gh-pages branch of your projects with the website.


Previously, I just dumped workflows like this one in a folder on my deanishe.net webserver (and before that in my Dropbox public folder, when it still worked).


I just recently decided it'd make more sense to put them on my website where I can add a bit of context, not least to remind me what the workflow does.

 

2 hours ago, nikivi said:

Can you share how you setup your workflow for it?

 

There isn't really a workflow. I don't do it often enough for it to be worth automating. Previously, I just used a ForkLift bookmark to open the relevant folder on my webserver. Now, I've written a Hugo template that shows a download link for any resource file that isn't an image. (Hugo resources are any files in the same directory as a post's index.md.)

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