Jump to content

Cedric

Member
  • Content Count

    33
  • Joined

  • Last visited

  • Days Won

    2

Cedric last won the day on June 22 2016

Cedric had the most liked content!

About Cedric

  • Rank
    Member

Profile Information

  • Location
    France

Recent Profile Visitors

747 profile views
  1. Hey, Just wanted to say that it works perfectly for me. Thanks so much for the workflow and its beautiful documentation. Best, OSX 10.11.5 El Capitan Macbook Air mid-2011 Alfred 3
  2. Thanks so much for the response, it's so much clearer now. A lot of things weren't obvious to me, like the part about "modelled on the requests library" meaning that it worked exactly the same way. Because I didn't understand how Alfred worked, the part of the code about grabbing the query went over my head, as I didn't understand what the code was doing. Here is why I'm using the print function: my goal with the v0.1 of the workflow was to be able to display (print) very simply the answer to the question "male or female?" I naively thought that I could write a v0.1 my Python script and easily integrate it into Alfred, and iterate from there. Obviously, there are too many hurdles in doing that, so I will: - finalise the script (by making sure my code works when the API returns errors or the like). - integrate it into Alfred by using your library Thanks for the clarification, really. I'm going to post again here when I'm done rewriting the code.
  3. I've already read it twice before posting (along with Alfred-workflow documentation and the bundler code comments and documentation, and other forum posts), I do try to do my homework before asking for help! The tutorial does not do exactly what I'm trying to do, as I'm not trying to show a list of posts. It might be why the answer didn't seem so obvious to me. But I guess I'll take a small break and re-read it again, maybe taking a step back will help seeing the answers there. Thanks a lot for your help, sorry if it seemed like I was trying to make your write the tutorial again.
  4. Thanks for the quick reply! About the error in the code I'm not sure I understand what's happening: I tested the code in iPython, and it works. I then tested the worfklow while using fixed values ('Alice Nicolas' instead of '{query}') and it works. When I'm using it with {query} it doesn't work. Here is the error message, for reference: [ERROR: alfred.workflow.action.script] Traceback (most recent call last): File "genderize.py", line 36, in <module> proba = [float(r.json()[p]['probability']) for p in range(len(values))] KeyError: 0 About passing the query I'm not sure I understand exactly how do I pass the query. In the other workflow that I wrote in bash, I knew that scrip.sh word makes 'word' a positional parameter that I can grab in the code. For python, I don't know how to tell Alfred "replace the {query} in the code with my input". I thought it was managed automatically. About the problems with the code I know that my code doesn't work if the API returns errors, I went for a first version that would allow me to test creating a working workflow in Alfred. Once i can do that, I will focus on making the code stronger. I'm a beginner at Python, so I don't have the best practices yet in regards to querying API. About alfred-wofklow It's included in the folder at the moment, but not used. I plan to review the tutorials later to see how I can adapt the code to my needs if I want to complexify the workflow. Working with requests first was a good way to learn a popular Python module that I will probably use in other projects.
  5. Thanks a lot for the tips, and especially for the aliases. pip now works as it should and I successfully installed Requests in the worfklow. I do have a message about pip not being up to date, should I try to update it? It seems to be in the system folder. That said, my workflow still does not work. I tried using the script filter, but Alfred would display fallback options (Google...) before I'm able to finish typing the names. I then tried with the other script object, but nothing happens. If you could give it a look and tell me what's wrong, that would be really helpful. Here is the link. Thanks!
  6. I'm trying to create a Python workflow that would work with the API of https://genderize.io In my Python code I use the "requests" and "collections" modules. The code works as intended when ran through the Python interpreter, but now I don't know how to actually finalize the worfklow and include the dependencies. I tried using the Python dependency bundler, but it didn't seem to work. I tried to pip install inside the workflow folder, but I have the Homebrew related bug with the pip install --target=url. I used a technique which did install requests in the workflow, but I'm not sure how to point to it now. I'm very confused despite my best efforts, and the workflow folders reflect that. Hopefully someone can walk me though the correct steps to do once the code is written and working. Thanks! Here is the workflow: link And the code: #!/usr/bin/env python # encoding: utf-8 #Code under MIT lience, modified from Stack Overflow answers, as listed below: #orlp http://stackoverflow.com/a/19560097 #Aaron Hall http://stackoverflow.com/a/33737067 #metatoaster http://stackoverflow.com/a/25480206 #Ultimate Zero http://stackoverflow.com/a/13224079 import requests from collections import OrderedDict import bundler bundler.init() #1.PREPARING THE QUERY #import Alfred's query query = '{query}' #transform query into a list values = query.split() #format the keys as expect by genderize.io keys = ['name' + '[' + str(i) + ']' for i in range(len(values))] #create the parameters as an ordered dictionary of keys and values, as expected by requests.get() names = OrderedDict([(k, v) for k, v in zip(keys, values)]) #2. SENDING THE QUERY AND FORMATTING THE RESULTS #query the API with the GET request r = requests.get('https://api.genderize.io/', params=names) #define a function to easily access probability. proba = [float(r.json()[p]['probability']) for p in range(len(values))] #define a function to easily access count. count = [int(r.json()[c]['count']) for c in range(len(values))] #define a function to easily access gender. gender = [str(r.json()[g]['gender']) for g in range(len(values))] #3. PROCESSING THE RESULTS #print the results of the query, with some variations linked to the strenght of the guess for r in range(len(values)): if proba[r] >= 0.9: print values[r], 'is most likely', gender[r] elif 0.7 <= proba[r] < 0.9: print values[r], 'is probably', gender[r] elif 0.5 < probar[r] < 0.7: print values[r], 'is maybe', gender[r] else: 'the gender of', values[r], 'is unknown'
  7. Hello, Thanks for this amazing worfklow. I'm a big pocket user (top 1% reader according to their stats) but both the mac app and the firefox extension were failing me (the firefox extension doesn't work when you don't save your history). I'm not sure how the "save link from clipboard" works though. I activated the global shortcut, but nothing much happens. How is it supposed to work? Should the link appear in alfred with the option to "save to pocket"? or does it work in the background with no feedback to the user? By the way, you should mention in the description that users have to set the global hotkey themselves; this is the normal behaviour of Alfred to avoid conflicts with other system hotkeys. Cheers
  8. Could you give me some pointer about how to set the language? I'm not sure where to start to make this happen. Thanks!
  9. I have completely rewritten my workflow to make it work even if the project name contains one or more space. The code doesn't care, and simply checks that a section number is correctly entered. I did as you said as well, and got the .sh script on a dedicated file, using /bin myscript.sh {query} to set the positional parameters. This workflow now works exactly as intended, thank you for your help! #!/bin/bash #code under MIT licence, modified from Stack Overflow, Unix.com and Ask Ubuntu answers, from the users below: #bashist http://stackoverflow.com/a/6968547 #Ignacio Vazquez-Abrams http://stackoverflow.com/a/2210386 #robotronic http://www.unix.com/shell-programming-and-scripting/42417-what-does-mean-double-pipe.html #geirha http://askubuntu.com/a/29596 #the positional parameters are set from Alfred's script filter #test if the last parameter is a valid integer. if [[ ${@: -1} =~ ^[0-9]+$ ]]; then #run the automator workflow. ${@:1:($#-1)} = All parameters but the last; {@: -1} = last parameter automator -D project_name="${@:1:($#-1)}" -D section_number="${@: -1}" folder_cleanup.workflow #If the last parameter was not a valid integer, send a notification else echo 'Incorrect section number? Try again' fi
  10. You're right, my workflow was confused. I now edited the automator workflow and here is the script that Alfred runs. #!/bin/bash arr="{query}" set -- $arr automator -D project_name="$1" -D section_number="$2" /Users/.../Alfred.alfredpreferences/workflows/.../folder_cleanup.workflow And it's working beautifully! This is great, and all the files are in the worfklow so it will work on my other computers. This shows that with even with my limited coding knowledge, I can create interesting workflows, at least for my personal use. I'll definitly think about doing more of them in the future. The mistake that kept me blocked was silly, and I accidentally closed the page while writing about it, which is sillier. So I'll edit this response when I have the time to add the full explanation. A question: is it possible to give the automator function a relative path to the workflow, rather than the absolute one? Second question: My workflow requires two arguments separated by a space (that Alfred recognizes as a single argument with a space inside). How could I modify the script so it tells me if I forgot to put 2 arguments? Maybe counting the number of array items, and using an IF? IF array != 2, echo {error_message}. I understand that the echo becomes another {query} than can be passed to a notification that would show warn the user? Thanks for your help!
  11. This is great, thanks a lot! This is an example I will be able to tweak in the future for similar needs, which is awesome. What I wanted to do was: Be able to find an English function name, with the subtitle showing the description From there, be able to display the French translation of the function, and copy it in the clipboard Additionnaly I would have been able to open the English description webpage of the function using a modifier like ALT+ENTER What I tried to do was: Display the list of functions in Alfred (with their description as subtitle), so I could filter them Display the French translation using a modifier, like CMD Copy the translation using CMD+ENTER This is why I added these to my xml <subtitle mod="cmd">Translation in user selected language</subtitle> <text type="copy">Translation copied in clipboard</text> But it clearly didn't work. What I wish I could do, ideally, would be To be able to set the second language with which I want the worfklow to work (e.g. with a XLANG [language] command) Then be able to search for an English function, with the subtitle showing the description (e.g. with an XL command) From there, be able to show the translation of the function in the user-defined language (via XLANG) and copy it in the clipboard Additionally, the workflow would At step 2, allow me to open a webpage with the English description of the function using a modifier like ALT+ENTERI took into consideration the fact that a 2-step process is hard to do currenly. I saw several worflows (Lastpass, Date Calculator, TimeZones) which allow a specific command to set user-defined parameters that affect other commands, so maybe it's easier that way? Thanks so much for your help.
  12. I resaved the app and saved it as a zip. Maybe Dropbox was doing something funny with it? I don't know why It said it was corrupted. I'm using El Capitan 10.11.3 btw. Did you successfullly use this automator line? I tried all combinations of capital or lower D and with and without quotes, and I had always the same result: The workflow DID skip the part for which I had entered an argument, and successfully started with the second question. But every time it sends me a feedback saying The action "Set Value of variable" wasn't given the correct data The second prompt that appears in the workflow is normally prefilled with the value entered via bash. But every time, I used automator -D, the second prompt does not have the value prefilled, and I get the error message. Thanks so much for following up on this!
  13. I did the initial app in Automator because I have a very limited knowledge of programming (copy/paste level). From there it seemed easier to try something in AppleScript, because they are somewhat related, and AppleScript. I have no special love for AppleScript, so maybe I can try to copy/past some python/ruby stuff. Or should I look at bash? Thanks!
  14. Thanks for your feedback! I'm not sure how the translation would fit there either. The simplest way I thought of would be to have the translation appear in the subtitle when pressing cmd while highligting a function. And pressing the CMD would copy the translated function. It appeared to me that it would be easy to encode this behaviour directly in the XML, which would mean that a CSV/XML converter would be all I needed, as long as I understood how Alfred expect its XML. The optimal way would be to have each function as a potential argument. It would look like: Step 1: Excel 1. ABS 2. ACCRINT Step 2: Excel ABS 1. French translation 2. Spanish translation 3. etc The Packal workflow has this behaviour, as a reference. But I don't have the skills to do that. I used an online CSV/XML converter (a bad one, I need to find a better one), and pasted the first bit of the resulting XML in the workflow. It works somewhat, but the CMD press does nothing so far. So nothing but the CSV, zero line of code. I wasn't sure about the UID, thanks for the tip.
  15. Hello, I managed to get a list of Excel functions with their translations in 15 languages I train people on spreadsheet usage in several languages, so I sometimes have to find the translated version of a function. My idea would be to have a workflow which would: 1. Display the full list of functions with their description 2. Display the translation for a given function in a user selected language 3. Copy the translation to the clipboard Of course, I have no idea on how to do that. I have a csv with all the data here. And I looked up the format Alfred works with, which is XML. It should look like this: <items> <item uid="function" arg="https://support.office.com/en-us/article/ABS-function-3420200f-5628-4e8c-99da-c99d7c87713c" valid="yes" autocomplete="ABS"> <title>ABS</title> <subtitle>Math and trigonometry: Returns the absolute value of a number</subtitle> <subtitle mod="cmd">Translation in user selected language</subtitle> <text type="copy">Translation copied in clipboard</text> </item> <item uid="function" arg="https://support.office.com/en-us/article/ACCRINT-function-fe45d089-6722-4fb3-9379-e1f911d8dc74" valid="yes" autocomplete="ACCRINT"> <title>ACCRINT</title> <subtitle>Financial: Returns the accrued interest for a security that pays periodic interest</subtitle> <subtitle mod="cmd">Translation in user selected language</subtitle> <text type="copy">Translation copied in clipboard</text> </item> </items> I used the workflow template to test this simple schema, but the link doesn't work. I didn't have much hope though, I have no relevant expertise. If someone wants to give it a go, I send you all my gratitude in advance. Thanks!
×
×
  • Create New...