Jump to content

Search the Community

Showing results for tags 'python'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Alfred 3
  • Make the Most of Alfred
    • Discussion & Help
    • Bug Reports
    • Alfred Feature Suggestions
    • Themes
  • Alfred Workflows
    • Share your Workflows
    • Workflow Help & Questions
  • Alfred v2 Themes
  • Alfred Remote for iOS
    • Alfred Remote Discussion & Help
    • Remote Connection Troubleshooting


  • Articles
    • Forum Integration
    • Frontpage
  • Pages
  • Miscellaneous
    • Databases
    • Templates
    • Media


  • New Features
  • Other

Found 69 results

  1. This workflow lets you control your Home Assistant from Alfred. You will be able to control you lights, get sensor information, trigger automations and look for your devices in device tracker. And more to come.. Setup _haurl - Set the URL to the home assistant. _hapassword - set the API password for Home Assistant Commands to interact with home assistant To triggar an automation: haa To control lights: hal To control your alarm: haal To look at a Sensor: has To look at device tracker had You will find the workflow here : https://github.com/Skakiz/Alfred-Home-assistant-workflow Lights: Automations: This is my first python coding, so no glitter code. Thanks! //Andreas
  2. Modifying Workflow Script

    Hi, So I'm a newbie, but I've managed to install Google assistant using terminal and can access it there. I want to use this alfred workflow http://www.packal.org/workflow/google-assistant to launch Google Assistant in the background but can't get the workflow to talk to python. Currently I have to type " source env/bin/activate and then: python -m googlesamples.assistant.grpc.pushtotalk The way the workflow is originally does not correspond to the steps I take to launch Google Assistant using Terminal. Can someone help me modify the workflow script to allow me to use Alfred to trigger Google Assistant? Many Thanks, Stephan
  3. Hi guys. I tries to make a workflow which launches my own python script. Script accepts exact 2 arguments. What is the best way to do that?
  4. There is a bug in my (unofficial) Alfred-Workflow library that causes very many workflows using it to hang quite dramatically on Sierra. If you are affected (i.e. you see Alfred's CPU usage spike to 100%), Activity Monitor will show two Python processes like this (choose View > All Processes, Hierarchically), with the bottom one at ~99% CPU (this screenshot is actually of a non-misbehaving workflow): Download and run this workflow, which will update any old versions of Alfred-Workflow in your installed workflows. That should get your workflows working again until the workflow developers can push official fixes.
  5. Hi, I'm working on my first workflow. The goal is to connect the Keyword "shifts" to: 1) Navigating to a specific folder; 2) Run a python script which is in there (script prompts user for 2 dates in format YYYY-MM-DD) 3) Enter today's date in the format YYY-MM-DD; 4) Enter tomorrow's date in the format YYY-MM-DD; I've managed to do it up to, and including, step 2. However, I don't know how to enter today's date (whichever date today is) programatically in the workflow. I've tested with dummy data (entering two dates in the format) and it works fine so it's just a matter of making it a variable I guess. Any ideas on how to do this? Cheers!
  6. Python Interpreter

    Hey everyone, Here's a workflow I created a while ago and have been using quite alot myself: Alfred Workflow: Python Interpreter The full power of python at your fingertips.Evaluate or run python commands directly from Alfred. Hit enter to copy output to clipboard. This workflow automatically imports the following standard libraries as star-imports: math, random, re, calendar, os.path, shutil, json, time, macostools. Furthermore it attempts to import numpy as star import and ignores it silently if not installed. Get it here: https://github.com/altre/alfred_python_interpreter http://www.packal.org/workflow/python-interpreter
  7. Hi all, I use Clear for my todo list manager on macOS http://www.theverge.com/2012/11/7/3613664/clear-for-mac-review. I wrote a helpful script show me how many todo items I have for the given day, script here: https://ghostbin.com/paste/zuc94 When I run the script as a local alfred script, it works perfectly. However, if I copy the same code to a file on disk and attempt to run it as an external script, I never get a notification. My setup is below, am I missing something obvious? Thanks in advance
  8. I'm having a difficulty with using Alfred to filter script results I have a python script that queries an internal wiki #!/usr/bin/env python from __future__ import print_function import sys from workflow.workflow3 import Workflow3 from workflow import web QUERY_URL = 'http://MYCOMPANY.ORG/mediawiki/api.php?action=opensearch&format=json&search={}&namespace=0&limit=50&suggest=' PAGE_URL = 'https://MYCOMPANY.ORG/mediawiki/index.php?search={}&title=Special%3ASearch' def main(wf): Workflow3().logger.info(wf.args[0]) Workflow3().logger.info("HI") query = str(wf.args[0]).replace(' ', '%20') results = web.get(QUERY_URL.format(query)).json() for keyword in results[1]: url = PAGE_URL.format(keyword.replace(' ', '+')) wf.add_item(keyword, '', arg=url, copytext=url, icon='logo.png', valid=True) wf.send_feedback() if __name__ == '__main__': wf = Workflow3() sys.exit(wf.run(main)) I have this in a script filter and if I run with bash and use the command: python wiki.py $1 Everything works fine. If i select "Alfred filter results" I get the following error Is there something different in the way the script is being called if i have the Alfred filter results button pressed? I'm assuming the query parameter is perhaps passed differently? Any insight?
  9. I have a script filter that outputs a value. When passing this value into a downstream script filter, the argument is only available (via sys.argv) if the "Alfred filters results" box is unchecked. When checked sys.argv[1] throws an index out of bounds error. When not checked, the argument is available as expected.
  10. Good morning, I'm currently trying to create a simple Script Filter Alfred 3 Workflow using Python. I found an earlier example which demonstrated how to pass XML results to a Python workflow: xmloutput = """ <?xml version="1.0" encoding="utf-8" ?> <items> <item arg="testitem"> <title>FooBar</title> <subtitle>foo bar is a test item</subtitle> <icon>icon.png</icon> </item> </items> """ print(xmloutput) My question is, what is the syntax for doing the same with the new JSON data structure? regards, Andrew
  11. hello, I am trying to create a workflow for a projectmanagement tool 10.000ft that gives me fast acces to specific project pages on the web. It currently lists all the projects and I have different keywords to start the workflow with different outcomes, 10kpe opens the project in edit mode while 10kpv opens the project in view mode. This is not very user-friendly and developer friendly :-). Since I am not a very experienced developer I cannot figure out what the best way is to create a 'sub-menu' of actions/options after selecting something from the first list. A second option that would be nicer than the current solution could be using different actions with the modifier keys (alt for editing, ctrl for running a report etc.). I went through the documentation, forums etc, even tried reading through different scripts like searchio but it's a bit to complex for me know :-) can someone give me a clear/simple example of both? I'm writing it in python using the alfred-workflow by deanishe. My code can be found here: https://github.com/jceelen/alfred-10000ft-scripts
  12. I'm new to Alfred workflows, json and python, so I'm more or less starting from scratch on this one! I want to create a workflow that will get the latest bitcoin price in GBP, using the bitcoinaverage API (https://api.bitcoinaverage.com/ticker/global/GBP/). That gives me a json file that looks something like this: { "24h_avg": 473.32, "ask": 498.26, "bid": 497.76, "last": 498.02, "timestamp": "Mon, 13 Jun 2016 14:26:07 -0000", "volume_btc": 1703.35, "volume_percent": 0.7 } I would like to have a simple python script that will query the API, extract the "bid" value and then give it back to me in Alfred. I'm trying to base my script off the Pinboard tutorial but it's not working so far. Can anyone help?
  13. I have a weird problem with my workflow. It does not show any results in Alfred but works when run from Terminal. But let me explain more on that topic. My workflow's job is to list Polish cities from webpage (get the list from JSON results from page) and download detailed weather forecast as png file. The main script is written in Python. The thing is, Polish cites also uses diacritical letters (ą, ć, ę, ł, ń, ó, ś, ź, ż). And when I want to use my workflow with city that contain one or more of mentioned letters – say <code>Gdańsk</code> the workflow itself won't work – just shows the result prepared for situation when no results find. However, when I debug the script from Terminal: python script.py "Gdańsk" I got all of the XML code for results: <?xml version="1.0"?><items> <item> <arg>http://m.meteo.pl/warszawa/weather;Warszawa</arg> <title>Ostatni → Warszawa</title> <subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle> <subtitle mod="cmd">Prognoza 84h.</subtitle> </item> <item autocomplete="Gdańsk"> <arg>http://m.meteo.pl/gdansk/weather;Gdańsk</arg> <title>Gdańsk</title> <subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle> <subtitle mod="cmd">Prognoza 84h.</subtitle> </item> <item autocomplete="Nowy Dwór Gdański"> <arg>http://m.meteo.pl/nowy-dwor-gdanski/weather;Nowy Dwór Gdański</arg> <title>Nowy Dwór Gdański</title> <subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle> <subtitle mod="cmd">Prognoza 84h.</subtitle> </item> <item autocomplete="Pruszcz Gdański"> <arg>http://m.meteo.pl/pruszcz-gdanski/weather;Pruszcz Gdański</arg> <title>Pruszcz Gdański</title> <subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle> <subtitle mod="cmd">Prognoza 84h.</subtitle> </item> <item autocomplete="Starogard Gdański"> <arg>http://m.meteo.pl/starogard-gdanski/weather;Starogard Gdański</arg> <title>Starogard Gdański</title> <subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle> <subtitle mod="cmd">Prognoza 84h.</subtitle> </item> </items> Notice that first item group is previously used city. But all the other show results with name "Gdańsk". And that is behavior, when the option in Script Filter – Alfred filters results is unchecked. When I check that, all seems to work fine. So why am I bothering you at all? Because I rather want to uncheck that option – it affects situations when I want to not display any results (in some cases). So I want to ask you for help with that problem. Maybe there is some encoding problem in Alfred 3 itself? The workflow can be downloaded here. Just copy and paste "Gdańsk" to debug it.
  14. There are currently several methods for packaging workflows, all with advantages and disadvantages of course. For example: deanishe uses a script similar to: https://gist.github.com/deanishe/b16f018119ef3fe951af documents the export function within Alfred itself: https://alfredworkflow.readthedocs.org/en/latest/tutorial_2.html#sharing-your-workflow shawnrice appears to use a shell script: https://github.com/shawnrice/packal-updater/blob/master/alfred.bundler.sh Wolph (me) uses a Makefile: https://github.com/WoLpH/alfred-converter/blob/master/Makefile It seems to me that there is a better solution though. The setuptools package is widely used within the Python community to compile, build and deploy packages to the PyPI servers but it can do more. The Sphinx-PyPI-upload-2 package for example (https://github.com/WoLpH/sphinx-pypi-upload) makes it possible to upload Sphinx documentation to the PyPI servers which can be built using the commands from Sphinx itself. With that regard I propose a new solution for packaging Alfred workflows: Use entry_points to create a bdist_alfred command similar to bdist_wheel (https://wheel.readthedocs.org/) Create a upload_packal command similar to upload_sphinx (https://github.com/WoLpH/sphinx-pypi-upload/blob/master/setup.py#L32-L36) Create a standard for specifying Alfred entry points through the setup.py
  15. Unicode input to python script

    I'm trying to pass in a character like γ into a python script through alfred, (as well as use it as a dict key within that script). I keep getting the error 'ascii' codec can't decode byte 0xce in position 0: ordinal not in range(128). Does anyone know what this is about, or how I can achieve unicode character input into a python script?
  16. I've created some workflows that run Python scripts stored at some specific locations. In general, everything's going fine, but there's one thing that's bothering me a bit: I'm running them by choosing "Run Script," selecting the language as Bash, and then entering the script as "/usr/bin/python script_location script_parameters." This just seems clumsy to me because Alfred actually can call the Python interpreter directly, instead of through bash like this. The problem is simply that the "Run Script" dialog has no way to specify a location of a script: you can only specify the actual contents of the script. I don't actually want to store the Python script itself inside the workflow. Does this seem odd to anyone else? Anyone have any solutions?
  17. So this is my first time working with python and alfred scripts. So please bear with me. I was using deanishe's guide on creating a python script - but having some issues with the python script import sys import phonenumbers import geocoded x = "'{query}'" # input needs to be wrapped in quotes-is this called correctly? z = phonenumbers.parse(x, "US") phonenumbers.format_number(z, phonenumbers.PhoneNumberFormat.NATIONAL) # How do I return result into alfred? I'm using Googles Python Library phonenumbers https://github.com/daviddrysdale/python-phonenumbers
  18. I'm trying to make my workflow robust against special characters, and I'm having a bit of trouble. When I run my python script from the terminal with an argument containing special characters it works fine. Eg: python alfredwl.py show "a´´´´ÅÅÅ´´ÅÎÎÎÏÍÒˆ„ÏıÔÍÓÔÍÏıÅͯÅÍåå∂ß˚˜≤√åß" However, when I run it through Alfred as "wlshow a´´´´ÅÅÅ´´ÅÎÎÎÏÍÒˆ„ÏıÔÍÓÔÍÏıÅͯÅÍåå∂ß˚˜≤√åß" in a script filter my workflow seems to stumble on the character encoding. In my python script I convert arguments from UTF-8 into Unicode strings--I figured that would've worked for Alfred. What type of encoded string does Alfred's script filter pass onto the Bash script running? Thanks, Nick
  19. Hi everyone, I created a simple workflow to interact with Wunderlist. It allows you to add tasks, show your lists, and show incomplete tasks through Alfred. It has just a couple keyword commands: "wladd" and "wlshow". For more info and to get the workflow, check it out on Packal or Github. Let me know what you guys think! Nick
  20. Background I use a workflow to search Omnifocus data direct from Alfred. This is a Python script using deanishe's alfred-workflow. This works well but I've spotted an odd edge case: * invoke the workflow and pass it a single character query (e.g. .s e) * nothing happens other than alfred creating a python process which is left stale * no output shown in alfred workflow debugger * providing a longer query does work Is this a known issue or expected behaviour? Details Alfred version & build number: v2.7.1 (387) OS X version: 10.9.4 Reproducible: Yes, here's a video demonstrating the problem. Script Filter settings Steps to reproduce Assumption: you have Omnifocus installed. Install v1.1.2 of the workflow Invoke the workflow '.s' with query 'e' Results: Alfred debugger will show no output Stale python process shown when running ps aux | grep python
  21. Anki Workflow

    My initial attempt at an Anki workflow. More to come after boards (have to put away addicting things such as Alfred ). I welcome any and all suggestions. Download, GitHub, Packal. Requirements: Alfred Anki Commands: :anki :aset :apath Anki Terminology: Collection = Group of Decks Notes = Collection of Facts Cards = Representation of Facts A note has a one to many relationship with cards, while a card can have only one associated note. Custom Dark Theme: Cards (notes) created from the workflow use this theme. Once the first card is created (from within workflow) the theme is available within Anki. The theme comes loaded with jQuery v1.11.2 and plugins Zoom, Magnific Popup, Panzoom (mobile only), and Noty. You can find it in Anki under Tools > Manage Note Types > Alfred Dark. If creating cards from inside Anki the theme has optional fields. Front, F NoteFront side, and optional note Back, B NoteBack side and optional note classThe theme default is to center all text. To adjust text to the left enter left in the class field. NotyShow an optional note on the back-side of the card. Good for reinforcement. httpEntering a URL in this field displays a link in the bottom right on the back-side. Accepts www.site.com without http video - Accepts youtube and vimeo urls. Link to the video is displayed in the upper left on the back-side. Workflow Progression: 1. :aset As of now contains two actionable items.Update collection (manual collection refresh) Set Anki collection path (redirects to :apath) :apathThe workflow looks for the Anki collection in the most typical locations. If the path is not found the user will be prompted to enter the path manually.The default directory is /Users/OSX_NAME/Documents/ANKI_USER/collection.anki2 The default ANKI_USER created when Anki is first run is User 1. If you have changed this, enter your Anki user name. If the path is found :apath is only useful if needing to switch between collections. 2. :anki Search the collection for a deckSearch by name, or deck id If the deck doesn’t exist you can create a new deck with the query as the title. Select deck Search for notes within selected deckSearch by facts, or tags If the card is not found you can create a basic, two-sided card (cloze additions on the to-do list). The theme is the custom dark theme described above. Select cardCurrently the only option after selecting a card is to modify its tags. tags are entered as #tag1 #tag2 #tag3 Credits: This workflow uses the python workflow library Alfred-Workflow (by deanishe). The internal structure borrows *heavily* from the FuzzyFolders and Reddit workflows (also by deanishe). The new_card.py was written by (guess who) deanishe, as a demo for my edification. TO-DO: Anki Sync File Action to import csv’s Sort decks by new, reviewing, missed More robust display of deck/card statistics Open Anki to a specific deck Choose model (theme) when adding cards Allow for cloze cards Rename decks
  22. Any workflow that uses python just doesn't work. I tried reinstalling python (2.7.9), but didn't seem to help. Checked the console to see if any errors were being outputted but didn't look like it. All other workflows work great... anyone experience this or know how to fix it?? thanks!
  23. Anki Workflow

    I have a few questions regarding workflow structure, storage, and python how-to's. Anki is a flashcard program, it is written in python, and has a sqlite database. 1. In order to connect to the database I need to supply a path. Since I'm using the Anki module alone (without anki's version of PyQt, aqt), I have to supply the path manually. The way I'm doing this is rather costly, and I would like to "store" the path after a successful connection is made, so further instances of the workflow have access to and use this path. Below, I've covered the most likely paths to Anki, but at a later time I would like to ask the user, through Alfred, to input the path if an error occurs. As a point of style, is it customary to import a module within a def? def get_col(): default_locations = [ os.environ['HOME']+'/Anki/User 1/collection.anki2', os.environ['HOME']+'/.anki/User 1/collection.anki2', 'collection.anki2' ] for location in default_locations: if os.path.exists(location): return location else: import glob home_path = os.path.expanduser('~') pattern = (home_path + '/**' + '/Anki' + '/*' + '/collection.anki2') for path in glob.glob(pattern): return path 2. When a result is selected with Alfred, and passed to the next script as the query, how can I get the result of the second script to display in Alfred? The wf.add_item doesn't seem to do it. The script 2, at the end of the post, should display the card count. 3. Besides querying Anki's database, eventually I would like to add cards from Alfred. The flow of the workflow ideally would be to first select a deck, and then options and deck statistics would display below in the results area. One option would be to add a card to the selected deck. After choosing "Add Card" the user would type in the front side, and by some magic of python, the front side text would display as the first result, the input area would clear and allow for the backside to be entered, which would display as the second result before submitting the change. This is why I'm asking for suggestions for structure. Is there a best way to account for these options by structuring the workflow a particular way? Further down the road I could allow for changes to the front or back after the initial input so that mistakes on card entry could be corrected. And much further down, I could allow for images to be attached with Alfred's file action. I've been playing with Anki heavily, I've authored a addon, HTML 2 ANKI (repo), and generally feel confident to start merging what I've learned into an Alfred workflow. 4. Within the workflow I've supplied the Anki module, but to import the module I first have to append the path with sys.path.append, else I receive errors, or run the script from the Anki folder. I did make sure to include __init__.py in all subfolders, however, the Anki module's __init__.py is not empty, and this seems to be the source of my frustration. I won't need the module until I start adding cards with Alfred (Anki says that doing it through the database is not recommended, mentioning that when updating Anki issues may arise), but I wanted to know if appending the path is acceptable here. I'll be sitting for step1 this summer, so I'm just trying to form a plan at this point, but afterwards I'd like to get this going. Anki's popular for people learning new languages, and med students, so I'm hoping it will be of use for a few people. As always suggestions are most appreciated. Script 1: # -*- coding: utf-8 -*- # [Run from subdirectory] import os, sys #abspath = os.path.abspath(__file__) #dname = os.path.dirname(abspath) + '/main' #sys.path.append(dname) # [IMPORT] import re import sqlite3 import json #from anki import storage, stats #from BeautifulSoup import BeautifulSoup, Comment, NavigableString from workflow import Workflow log = None def get_col(): default_locations = [ os.environ['HOME']+'/Anki/User 1/collection.anki2', os.environ['HOME']+'/.anki/User 1/collection.anki2', 'collection.anki2' ] for location in default_locations: if os.path.exists(location): return location else: import glob home_path = os.path.expanduser('~') pattern = (home_path + '/**' + '/Anki' + '/*' + '/collection.anki2') for path in glob.glob(pattern): return path return None def db_decks(db): results =[] deck_db = db.execute("SELECT decks FROM col") decks = json.loads(deck_db.fetchone()[0]) for d in decks.items(): deck = {'title': None, 'id': None} deck['title'] = d[1]['name'] deck['id'] = d[0] log.debug(deck) if deck['id'] is None: continue results.append(deck) return results def key_for_deck(deck): return '{} {}'.format(deck['title'], deck['id']) def main(wf): query = None if len(wf.args): query = wf.args[0] apath = get_col() connection = sqlite3.connect(apath) decks = db_decks(connection) if query: decks = wf.filter(query, decks, key_for_deck) if not decks: wf.add_item('No items', icon=ICON_WARNING) for deck in decks: wf.add_item( title = deck['title'], subtitle = deck['id'], arg = deck['id'] + ' ' + deck['title'] + ' ' + apath, valid = True, icon = 'icon.png') wf.send_feedback() if __name__ == '__main__': wf = Workflow() log = wf.logger sys.exit(wf.run(main)) Script 2: 1. How can I get it's result to display in Alfred? 2. With very large decks (many cards), I get an error saying so, I'm thinking this is the sqlite, ideas? # -*- coding: utf-8 -*- import os, sys, re import sqlite3, json from workflow import Workflow log = None def db_cards(db, did): cards_did = db.execute("SELECT COUNT(*) " "FROM cards " "WHERE cards.did = ?", (did,) ) card_count = cards_did.fetchone() result = card_count[0] return result def main(wf): did, d_title, apath = wf.args[0].split() connection = sqlite3.connect(apath) count = db_cards(connection, did) wf.add_item( title=d_title, subtitle=unicode(count), arg=did, valid=True, icon='icon.png') wf.send_feedback() if __name__ == '__main__': wf = Workflow() log = wf.logger sys.exit(wf.run(main))
  24. Any python workflow using locale.getdefaultlocale() will crash in Alfred 2.7 due to an unhandled exception. Since the python docs do not suggest that it is even possible for an exception to be thrown from that function, I do not imagine anyone wrapped this in a try block. I received some bug reports this weekend from some pre-release path folks who were seeing errors about unknown locale: UTF-8. I noticed in the release notes for the latest Alfred that the following change was made: • Add LC_CTYPE=UTF-8 encoding to script environment However, UTF-8 is not a valid value for this flag. Is this something that can be reverted or is there some case where it actually works? As a temporary workaround I was able to redefine LC_CTYPE in each of the bash scripts in the workflow, but hopefully that should not be necessary going forward. export LC_CTYPE="$(defaults read -g AppleLocale).UTF-8" Download a simple workflow that tests this bug. Type lcctype in alfred then action the result – it should show your current locale in large type but will instead fail with an exception.
  25. Hello all, I would like to create a workflow to manipulate some numbers (for example, a decimal to hexadecimal converter). I currently have a keyword as an input, and a copy to clipboard as an output. I want to write the script between the input and the output in Python, but I'm having trouble. How do you pass parameters into the Python script, and how do you return a result to send to the output action? Thanks in advance!