vanderholm Posted July 9, 2015 Posted July 9, 2015 Hi, I am trying to make a hotkey triggered workflow that will match and substitute parts of the selected text with phrases in a custom dictionary. This dictionary would in the best of worlds be stored in as a sheet in Google Docs but could also be a locally stored CSV or whatever is best. I reckon making a simple perl script is the way forward, but I thought I would ask here before trying a perl forum. I found this promising Dictionary implementation at PerlMonks but it baffles my noobish skills. I imagine the code would have to be saved as a .pm file in the workflow folder and declared (use?) in the script (filter?). The lookup and substitute functions could then be used with the input query and the return pasted. I have tried to make a mockup of this workflow but I really have not much of an idea about bridging perl script and alfred, I will keep working on it and read up on workflow practices but thought I might ask for some pointers from here and maybe find out if I'm on the right track? --- Sidenote: As a working solution I have been using a hack of the "save a sequence of regexs" functionality in Matthew Lancellottis excellent RegEx Workflow. The final dictionary would have a couple of hundred substitution pairs but for testing the regex solution I compiled the following pairs. elsif( $c =~ /^mal$/ ){ $q =~ s/Sign./Signed/gi; $q =~ s/Olie på lærred./Oil on canvas./gi; $q =~ s/Lysmål /Visible size /gi; $q =~ s/Bladstørrelse /Sheet size /gi; } It would be much more convenient if the workflow would compile theses expressions from a simple set of values. Also, this workflow uses the clipboard text and not the selection as input. Sadly my programming skills are not up to the task of modding the RegEx workflow further and that might be a bit of an inelegant overkill. Please let me have any input you might be able to give.
deanishe Posted August 1, 2015 Posted August 1, 2015 Are you good with Perl? If not, you might want to consider using another language like Ruby or Python. They're a lot easier to use, and you'll get more help on here because they're much more popular with workflow authors. vanderholm 1
vanderholm Posted August 5, 2015 Author Posted August 5, 2015 OK, thanks. This is very helpful, I was wondering about the lack of response from the wonderful community. I am no good in any language, excepting maybe applescript. I will try to learn a bit and rethink. What are your thoughts about whether to look at Ruby or Python with regards to specific and general usefulness?
deanishe Posted August 5, 2015 Posted August 5, 2015 I'm going to invoke the power of Cunningham's Law a wee bit to get someone who knows Ruby well to answer your question, too… Absolutely Python. No question. It's much more readable than Ruby and has a much better community. When it comes to Alfred workflows in particular, my Alfred-Workflow library for Python is streets ahead of the Ruby competition in terms of how much of the grunt work it can take off your hands. There are awesome tutorials available for Python: Dive Into Python How to Think Like a Computer Scientist Learn Python the Hard Way (it's not actually hard) A Byte of Python And my own tutorial for writing workflows in Python with Alfred-Workflow. vanderholm 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now