Comments (11)
What exactly are you asking me to do?
There is no option to choose the Escaping options in the "with input as argv".
Escaping isn't necessary when using argv
.
from alfred-workflow.
In section "Adding a Script Filter" of the tutorial, under the "And enter the details for this action (the Escaping options don’t matter at the moment because our script currently doesn’t accept a query):" there is a screenshot.
In Alfred 4, the options for Escaping do not appear unless you manually select "with input a {query} in the dropdown menu".
Down in the same section, there is this sentence: "We’re going to create the pinboard.py script in a second. The Escaping options don’t matter for now because our Script Filter doesn’t accept an argument." I would add at the end of that phrase. (Note/Warning: If you are using Alfred 4, you might need to select "with input as {query}" in the dropdown menu to make the Escaping options appear. But don't worry now, as we will not be using them right now".
I was checking the repo contents, and I've seen the tutorial itself is at docs/tutorial_1.rst. If you prefer, I can create a pull request with suggested changes and you can review them.
from alfred-workflow.
If you prefer, I can create a pull request with suggested changes and you can review them.
I wouldn't bother at this point. The library needs rewriting for Catalina/Python 3.
from alfred-workflow.
I wouldn't bother at this point. The library needs rewriting for Catalina/Python 3.
Does that mean a rewrite for Python 3 is planned or not?
from alfred-workflow.
Does that mean a rewrite for Python 3 is planned or not?
Well, yes. That's why I'm advising against big updates to the current version.
It'll be almost a complete rewrite for Python 3 only, and it's going to look a lot more like a Pythonic version of my Go library than it will the current version.
I want to remove a lot of stuff. Obviously, the Alfred 2- and 3-specific code is going, but there are still a few other things I need to decide on, such as whether to drop support for JSON in the caching code.
My main goal, apart from tidying up the API, is to improve loading time.
I'm open to any input regarding the API, features and docs (especially #103).
from alfred-workflow.
Hmm. Perhaps something that would make it easier (or at least clearer) on how to write workflows that contain both Script Filter and Run Script actions. Today I always end up with a lot of deeply nested code. I'm not sure how this would work exactly, but the thought of it is nice.
from alfred-workflow.
Perhaps something that would make it easier (or at least clearer) on how to write workflows that contain both Script Filter and Run Script actions.
I have an idea for the next tutorial that will have more parts and be a more complex workflow, combining multiple (free) APIs. That should give people a better idea how to deal with lots of actions.
Today I always end up with a lot of deeply nested code.
How so? Do you have an example?
from alfred-workflow.
I have an idea for the next tutorial that will have more parts and be a more complex workflow, combining multiple (free) APIs. That should give people a better idea how to deal with lots of actions.
Perhaps a workflow that has two (or more) Script Filter actions that are connected sequentially. The first Script Filter would then trigger a secondary Script Filter displaying different options depending on which action was chosen in the first Script Filter. But then again, perhaps that would be a bit too much for a tutorial.
How so? Do you have an example?
Perhaps deeply nested is a bit of a stretch. I think my main point is that there are two very different ways of providing feedback to Alfred depending on whether the script is invoked by a Script Filter or a Run Script action. I typically end up with code like this:
if args.mode == 'something':
# do something
wf.send_feedback()
elif args.mode == 'something-else':
# do something else
v = Variables('blah')
print(v)
elif args.mode == 'something-else-entirely':
# do something else entirely
wf.send_feedback()
from alfred-workflow.
You can't really avoid all the if
… elif
clauses without a bit of "magic", but normally, once it starts getting complicated, you'd have each clause call a function instead of inlining the code:
if args.mode == 'something':
return do_something()
elif args.mode == 'something-else':
return do_something_else()
elif args.mode == 'something-else-entirely':
return do_something_else_entirely()
If you have a large number of "modes", you can use reflection to call functions based on the value of mode
:
def do_something():
print('did something')
def do_something_else():
print('did something else')
def do_something_else_entirely():
print('did something else entirely')
def run(mode):
name = 'do_' + mode.replace('-', '_')
func = globals().get(name)
if func:
return func()
raise ValueError('Unknown mode: ' + mode)
run(args.mode)
Or encapsulate your program in a class with the same technique:
class Program(object):
"""An example program."""
def do_something(self):
print('did something')
def do_something_else(self):
print('did something else')
def do_something_else_entirely(self):
print('did something else entirely')
def run(self, mode):
"""Call method for ``mode``."""
name = 'do_' + mode.replace('-', '_')
meth = getattr(self, name)
if meth:
return meth()
raise ValueError('Unknown mode: ' + mode)
p = Program()
p.run(args.mode)
from alfred-workflow.
I think I used a dictionary at one point to do something similar. I'll try to clean up my code. Thanks for the tips!
Looking forward to see what you come up with for the Python 3 version of alfred-workflow.
from alfred-workflow.
I think I used a dictionary at one point to do something similar
That works well, too. The advantage of using reflection is that you don't have to remember to add new functions to the dictionary.
My Zothero workflow is a pretty big one. That might be worth checking out as an example of how to structure a large workflow, even if the workflow itself isn't very interesting for you.
I tend to build my workflows as command-line programs, and it might be worth looking at other Python CLI programs, like beets.
from alfred-workflow.
Related Issues (20)
- Cache Image HOT 5
- Basic auth HOT 3
- Pass parameter to subprocess HOT 5
- set_config raises error when the bundle id is null HOT 4
- Setting only arg on Variables adds line break HOT 1
- will it support python3? HOT 1
- python3 has no cpickle HOT 1
- cant get output HOT 11
- chr() arg not in range(256) error when trying to use Beautiful Soup 4 HOT 1
- workflow:magic not working?
- API functionality question
- AlertCautionIcon.icns does not exist on Big Sur
- ERROR: [Script Filter] JSON error
- Google SDK
- Can't get Script Filter to find the pinboard.py file from the tutorial HOT 1
- [Feature request] Possible to open bookmarks from root?
- Not working on the latest MacOS 12.3 HOT 11
- How to fetch chrome cookie?
- Issues with notify.notify in release version HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alfred-workflow.