forgetfulfellow Posted October 1, 2013 Share Posted October 1, 2013 Hi, It seems that I have had trouble following the (simple) instructions I've seen on various messages in the forum. To explain my problem: Even though I printed the value that I wanted to return from my script, it was neither outputed in the "post notification" section or copied to my clipboard. My entire python script is: print {query} and the only code I have in "copy to clipboard" is: {query} as well as the text section in "post notification": {query} Yet nothing shows up! Could someone kindly point me to Alfred Documentation? It seems that my googling powers are not as great as I thought... Thanks! Link to comment
jdfwarrior Posted October 1, 2013 Share Posted October 1, 2013 Hi, It seems that I have had trouble following the (simple) instructions I've seen on various messages in the forum. To explain my problem: Even though I printed the value that I wanted to return from my script, it was neither outputed in the "post notification" section or copied to my clipboard. My entire python script is: print {query} and the only code I have in "copy to clipboard" is: {query} as well as the text section in "post notification": {query} Yet nothing shows up! Could someone kindly point me to Alfred Documentation? It seems that my googling powers are not as great as I thought... Thanks! What kind of Action item are you using? Run Script? Or are you attempting to use a Script Filter to send data to another step? Sorry if this question sounds ridiculous, I'm not trying to insult your intelligence or anything, it's just to eliminate the possibility that something simple was overlooked but.. You did remember to set the script Language in the settings for the item right? I hate to admit it but I sometimes fall victim to this. I click through too fast sometimes and forget to actually tell it what language I'm attempting to use. *hangs head in shame* Link to comment
forgetfulfellow Posted October 2, 2013 Author Share Posted October 2, 2013 What kind of Action item are you using? Run Script? Or are you attempting to use a Script Filter to send data to another step? Sorry if this question sounds ridiculous, I'm not trying to insult your intelligence or anything, it's just to eliminate the possibility that something simple was overlooked but.. You did remember to set the script Language in the settings for the item right? I hate to admit it but I sometimes fall victim to this. I click through too fast sometimes and forget to actually tell it what language I'm attempting to use. *hangs head in shame* Hi David, Don't worry, I seriously need all the error-checking I can get! This is my first workflow, so I'm open to all the questioning At the moment, I'm using a "keyboard -> script -> notification" template, with my script language set as /usr/bin/python. Also, I just figured out that I'm supposed to pass in the incoming query variable like this: "{query}" But may I ask why this is the case? Also, after figuring this argument problem out, I made appropriate changes to my code to accept this variable, but my code doesn't work. Currently, I would doubt the code itself (since I'm not proficient at coding) but I know 100% that it works with the terminal. I have a few leads on what might be wrong, but let me ask you some preliminary questions: Is the type of the "{query}" variable a string? Is there a difference as to whether I need to use urllib instead of urllib2 if I'm retrieving something from the web? Thanks! Link to comment
jdfwarrior Posted October 2, 2013 Share Posted October 2, 2013 Hi David, Don't worry, I seriously need all the error-checking I can get! This is my first workflow, so I'm open to all the questioning At the moment, I'm using a "keyboard -> script -> notification" template, with my script language set as /usr/bin/python. Also, I just figured out that I'm supposed to pass in the incoming query variable like this: "{query}" But may I ask why this is the case? Also, after figuring this argument problem out, I made appropriate changes to my code to accept this variable, but my code doesn't work. Currently, I would doubt the code itself (since I'm not proficient at coding) but I know 100% that it works with the terminal. I have a few leads on what might be wrong, but let me ask you some preliminary questions: Is the type of the "{query}" variable a string? Is there a difference as to whether I need to use urllib instead of urllib2 if I'm retrieving something from the web? Thanks! 1. Alfred passes it straight though so, think of {query} as a placeholder and not a variable. However you initialize the variable (or whatever your casting the value as) in the script, that's what it is. For instance, in Python, if I store it like... input = "{query}" Then yes, it is indeed a string. Without the quotes, it can be whatever type you want it to be though. 2. Alfred doesn't care which module you use. Just remember though, if you plan on distributing this workflow that you need to be careful what non-standard python modules you use within your code because the other users may not have that module available. If you haven't figured out how to pass the string through yet, I created a sample workflow for you to take a look at. It uses the exact same template that you mentioned (keyword->run script->notification). It takes something as input so, just type the 'pysample' keyword and then just type anything you want to pass to it. That will be used as a string, and passed to the notification. Check it out here. Let me know if you have any more questions or need any more help. Link to comment
forgetfulfellow Posted October 2, 2013 Author Share Posted October 2, 2013 Hi David, Thanks for the sample workflow; it seems that all my problems about input are pretty much solved. However, I have stumbled upon my main problem that I am extremely baffled at. So I know that this piece of code works 100% in the terminal. Basically, I'm creating an app that queries an API online (in this case a website containing the bible) and getting back plain-text. When I plug this code into a python file and run it from the terminal: import urllib2 import sys url = "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=proverbs+8:11&output-format=plain-text" page = urllib2.urlopen(url) print page.read() I get: ======================================================= Proverbs 8:11 [11]for wisdom is better than jewels, and all that you may desire cannot compare with her. However, when I plug this into Alfred, it seems that the output does not get properly passed along and returns nothing. Could you give me a clue as to what is malfunctioning? Thanks! Nolan Link to comment
jdfwarrior Posted October 2, 2013 Share Posted October 2, 2013 Hi David, Thanks for the sample workflow; it seems that all my problems about input are pretty much solved. However, I have stumbled upon my main problem that I am extremely baffled at. So I know that this piece of code works 100% in the terminal. Basically, I'm creating an app that queries an API online (in this case a website containing the bible) and getting back plain-text. When I plug this code into a python file and run it from the terminal: import urllib2 import sys url = "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=proverbs+8:11&output-format=plain-text" page = urllib2.urlopen(url) print page.read() I get: ======================================================= Proverbs 8:11 [11]for wisdom is better than jewels, and all that you may desire cannot compare with her. However, when I plug this into Alfred, it seems that the output does not get properly passed along and returns nothing. Could you give me a clue as to what is malfunctioning? Thanks! Nolan Nolan, using the workflow I created as a sample.. 1. In the keyword, I changed the "Argument Required" option to "No Argument" 2. In the Run Script, removed the code I used and pasted in your code exactly with no modifications. 3. Replaced the notification with an Output->Large Type and connected it up It showed the output perfectly in the Large Type window. It worked with the notification also, it just truncates the text shown because notifications don't stretch to fit whatever content you give it. If you were using Growl instead (and only with certain themes) you could make it show up in a notification and show the full content. Link to comment
forgetfulfellow Posted October 3, 2013 Author Share Posted October 3, 2013 Nolan, using the workflow I created as a sample.. 1. In the keyword, I changed the "Argument Required" option to "No Argument" 2. In the Run Script, removed the code I used and pasted in your code exactly with no modifications. 3. Replaced the notification with an Output->Large Type and connected it up It showed the output perfectly in the Large Type window. It worked with the notification also, it just truncates the text shown because notifications don't stretch to fit whatever content you give it. If you were using Growl instead (and only with certain themes) you could make it show up in a notification and show the full content. WOW! For some reason, it works in your workflow and not mine... But thank you so much! I got it to access the API with arguments, so I'm bug-free in the coding realm. Now I want to add submenu options (Allow header, allow verse number, allow chapter name, etc.) and I searched this "help forum" for 'submenu' but all I got was one post for the alfred file directory. Is there any official documentation on how to add options/submenus using python? I tried looking on the Alfred website, but I couldn't find much. Link to comment
jdfwarrior Posted October 4, 2013 Share Posted October 4, 2013 WOW! For some reason, it works in your workflow and not mine... But thank you so much! I got it to access the API with arguments, so I'm bug-free in the coding realm. Now I want to add submenu options (Allow header, allow verse number, allow chapter name, etc.) and I searched this "help forum" for 'submenu' but all I got was one post for the alfred file directory. Is there any official documentation on how to add options/submenus using python? I tried looking on the Alfred website, but I couldn't find much. I'm not sure what you mean.. are you wanting to select more than one? or just a single? Maybe something like this is what you are looking for? Link to comment
forgetfulfellow Posted October 4, 2013 Author Share Posted October 4, 2013 I'm not sure what you mean.. are you wanting to select more than one? or just a single? Maybe something like this is what you are looking for? Actually, I just found another one of your posts that is exactly what I was looking for: http://www.alfredforum.com/topic/5-generating-feedback-in-workflows/ thanks! Link to comment
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