Jump to content

Alfred5 Split Argument - Add Max Number of Splits


Recommended Posts

Hiya - it'd be great to add the option to the fab new Split Argument Utility in Workflows so that you can specify the max number of splits as per Python's split(). I'm using it to split an Alfred command that has two arguments separated by spaces, but the second argument can also contain multiple spaces and I only want it to split into two! Hopefully this is easy to implement. Hope that's useful.

 

Toodle Pip

Sam

 

Link to comment
Share on other sites

That sounds a bit too specific for a new GUI option and the expected behaviour won’t be obvious (e.g. JavaScript also has an optional limit on split but it discards the extras instead of mashing them together).

 

Because you already know about Python’s split, it’s easy to replicate it with a Run Script Action. Create one with language set to /usr/bin/python3 and leave the rest as the default. In the code:

 

import sys
import json

separated = sys.argv[1].split(",", 1)

json_object = { "alfredworkflow": { "arg": separated } }
print(json.dumps(json_object))

 

Save it as a prefab and you’re good to go to reuse it whenever you need.

 

You only have to change the split part of line 4, everything else remains the same. This works because you can pass a JSON between Alfred objects to modify them or send additional information. In this case, you’re just passing the arguments already split as you want.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...