manavortex Posted April 13, 2020 Share Posted April 13, 2020 (edited) Hello forum, What's the best practice for a workflow trigger (keyword or script filter) that uses an optional argument with a fallback value? Example 1 (I made this up): I want to more easily yell at people on the internet, so I have a workflow that turns text to caps. My clipboard is "foo". I call caps and expect my script to receive "foo". I call caps wasd and expect my script to receive "wasd". Example 2: Like example 1, but instead of the contents, I want to use hardcoded text. I call caps and expect my script to receive "your mother". ... What's the best practice to do that? This would be the in-script solution. Is there a built-in way to do this? import sys from AppKit import NSPasteboard, NSStringPboardType def getClipboard(): pb = NSPasteboard.generalPasteboard() pbstring = pb.stringForType_(NSStringPboardType) return u"Pastboard string: %s".encode("utf-8") % repr(pbstring) query = sys.argv[1] if len(sys.argv) >= 2 else getClipboard() # query = sys.argv[1] if len(sys.argv) >= 2 else "your mother" #example 2 sys.stdout.write(query.upper()) Edited April 13, 2020 by manavortex added example code Link to comment
deanishe Posted April 13, 2020 Share Posted April 13, 2020 An optional argument to a Script Filter only determines whether the Script Filter will be run before you've entered a query. You still have to action a result to pass control to the next action. With a Keyword, you probably want to set your default/fallback in code. You can do it in Alfred with a pair of conditionals, but that's a lot more complicated than just doing it in code. If it's something you think you'll change a lot, put it in a workflow variable so you can change it from the workflow's configuration sheet. manavortex 1 Link to comment
manavortex Posted April 13, 2020 Author Share Posted April 13, 2020 Hey deanishe, thank you for answering the question. Does it make sense to file a feature request for this? Link to comment
deanishe Posted April 13, 2020 Share Posted April 13, 2020 Doubt it. It's simple enough to do in Alfred already and entirely trivial in code. 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