Jump to content

Workflow for searching PubMed - problem


Recommended Posts

I have attempted to create a workflow that search Pubmed.org for scientific articles. The idea is to enter a string into Alfred 2 separated by commas and have a bash script parse the output so that it is formatted for searching the website. I'm doing this by triggering input with a keyword and then running the script. The output is an Applescript calling Alfred 2 to search for a keyword pointing at a second part of the workflow which is an "open URL" action. The problem is that when calling Alfred 2 back, sometimes it emulates pressing enter and sometimes not leaving Alfred 2 open with the parsed search string. I must have done something wrong with the Applescript. Suggestions is most welcome!

 

Bash script for parsing

echo '{query}'| awk '{split($0,array,",")} END{print array[1]"[ta] " array[2]"[vi] " array[3]"[pg]"}'

If I write Science,2,34 the parsed output will be Science[ta] 2[vi] 34[pg]

 

With the following Applescript I call another part of the workflow with the keyword "pmweb", and as I mentioned earlier, the key code 36 is not always working. If I manually press "Enter", the search is performed.

tell application "Alfred 2" to search "pmweb {query}"

tell application "System Events"
	key code 36

end tell

Link to comment

 

I have attempted to create a workflow that search Pubmed.org for scientific articles. The idea is to enter a string into Alfred 2 separated by commas and have a bash script parse the output so that it is formatted for searching the website. I'm doing this by triggering input with a keyword and then running the script. The output is an Applescript calling Alfred 2 to search for a keyword pointing at a second part of the workflow which is an "open URL" action. The problem is that when calling Alfred 2 back, sometimes it emulates pressing enter and sometimes not leaving Alfred 2 open with the parsed search string. I must have done something wrong with the Applescript. Suggestions is most welcome!

 

Bash script for parsing

echo '{query}'| awk '{split($0,array,",")} END{print array[1]"[ta] " array[2]"[vi] " array[3]"[pg]"}'

If I write Science,2,34 the parsed output will be Science[ta] 2[vi] 34[pg]

 

With the following Applescript I call another part of the workflow with the keyword "pmweb", and as I mentioned earlier, the key code 36 is not always working. If I manually press "Enter", the search is performed.

tell application "Alfred 2" to search "pmweb {query}"

tell application "System Events"
	key code 36

end tell

 

Not sure if you were aware of this or not but there is already a workflow available for searching Pubmed. See here. If you are still wanting to continue building your own though, let me know and I'll try to help you get it worked out.

Link to comment

Hi David!
Actually I looked at the workflow from the link you mention and it is not really what I'm after. I would like to write a string in Alfred in the format Journal,volume,page. Then my script parses that to Journal[ta] volume[vi] page[pg]. If you search PubMed with those terms it is almost impossible to fail in finding the article. This comes in handy when you know which article you are looking for and just need to find it (when you're write your thesis, which I should be doing). For those occasions when I would like to search PubMed the "regular way" I've set up a custom web search (not a workflow).

 

The problem I have is the second script. That is supposed to take the parsed output from the first script, put it into Alfred and then go on and search PubMed. However, most of the times it just puts the output into Alfreds search window but without "hitting enter" and performing the search. Sometimes Alfred is not even called back. Any ideas on how to format the Applescript?

 

Thanks for your time!

Link to comment

Hi David!

Actually I looked at the workflow from the link you mention and it is not really what I'm after. I would like to write a string in Alfred in the format Journal,volume,page. Then my script parses that to Journal[ta] volume[vi] page[pg]. If you search PubMed with those terms it is almost impossible to fail in finding the article. This comes in handy when you know which article you are looking for and just need to find it (when you're write your thesis, which I should be doing). For those occasions when I would like to search PubMed the "regular way" I've set up a custom web search (not a workflow).

 

The problem I have is the second script. That is supposed to take the parsed output from the first script, put it into Alfred and then go on and search PubMed. However, most of the times it just puts the output into Alfreds search window but without "hitting enter" and performing the search. Sometimes Alfred is not even called back. Any ideas on how to format the Applescript?

 

Thanks for your time!

 

Ok cool, well then yeah I can help out for sure. One thing though, it sounds like you are using one part of the workflow to parse, and another to open a browser and search. Is that correct? Or are you using a script filter? 

 

Also, I believe that, with AppleScript you have to tell application System Events, the tell which process to send it to, so... Something like...

tell application "System Events"
  tell process "Alfred 2"
    key code 36
  end tell
end tell

I'm not sure about doing some of the parsing in AppleScript but I could easily do that with PHP. The PHP explode() function could split on the commas and built the correct URL. The only thing I was wondering though is, are you using a script filter to show live results in Alfred or are you just opening a URL?

Link to comment

Now it works! The workflow now takes my string, parses it and sends it to PubMed in my desired format. What was missing was the part in the AppleScript that told System Events in which process the tell should be sent to. Now it is time to share my first working workflow! Thanks for your help!

 

 

Cheers,

Tobias

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