Jump to content

Query database, return results to clipboard


Recommended Posts

Hello

 

I would like search the Chemical Identifier Resolver database and have the results returned to my clipboard. This seems like it should be a rudimentary task but I am having trouble getting the contents of the browser window onto my clipboard. Below is the custom search url I am using and an example query

 

http://cactus.nci.nih.gov/chemical/structure/{query}/cas

http://cactus.nci.nih.gov/chemical/structure/phenylalanine/cas

 

I was inspired by a post at Macs In Chemistry, and I would like to simplify their applescript by integrating alfred.

 

Desired order of operations:

Activate alfred

Type keyword (example: cas)

Type name of the chemical (example: phenylalanine)

Press return

Alfred retrieves the information from the database and clips it to my clipboard

 

Thanks for any help!

Link to comment

You will need to use a little code to get the text from the web. I know Python best, you could conceivably use anything that Alfred supports.

Setup

Create a Keyword Input (use cas as the keyword, require a query). Connect this to a Run Script Action. I would then write a script that uses something like this Python module to get whatever data you need. Pass that to a Copy to Clipboard Action and your done.

Obviously, the work-intensive part is writing the script, but that Python module seems to have that part pretty well figured out.

Link to comment

Thanks smarg19!

 

I'm new here and I am probably missing something obvious. I setup the workflow as you suggested. In the Run Script action, I set the language to /usr/bin/python and pasted the script into the Script textbox. Its not immediately clear to me how to format the query for this script. I have tried a number of different combinations including pasting from the test file provided on the GitHub. Below is the debug from the alfred workflow. Any help is greatly appreciated.

 

Best

 

[ERROR: alfred.workflow.action.script] ..F
======================================================================
FAIL: test_resolve (__main__.TestCIRpy)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<string>", line 35, in test_resolve
AssertionError: 'N[C@@H](C)C(=O)O' != 'CC(C(O)=O)N'


----------------------------------------------------------------------
Ran 3 tests in 0.290s


FAILED (failures=1)
[INFO: alfred.workflow.action.script] Processing output 'alfred.workflow.output.largetype' with arg ''
[INFO: alfred.workflow.action.script] Processing output 'alfred.workflow.output.clipboard' with arg ''

 

Link to comment

Hi Blake,

 

I quickly put together something which may be what your looking for: https://dl.dropboxusercontent.com/u/45099771/CIR-Example.alfredworkflow

 

Use "cir" with a keyword to perform a search. It will copy the result to your clipboard and display a notification.

 

I used the https://github.com/mcs07/CIRpy module linked above.

 

If you right click the addon > show in finder, you will see the source. Modify script.py to output whatever you want (see the print statement). You may want to change the desired output representation (again, see the github module documentation).

 

I'm sure you can figure the rest out :)

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