Jump to content

How to replace argument value in workflow


Recommended Posts

Hi everyone,

I am a brand new Alfred user and I love it!

However, it's my first time customising a workflow and tailoring it to my needs, and I'm a little perplexed.

 

Now I found a perfect script for my use (on this forum btw, thank you!) that allows me to put together and then open an URL by defining a set of argument:

 

query="{query}"

arg1=$(echo $query | cut -d " " -f 1)
arg2=$(echo $query | cut -d " " -f 2)
arg3=$(echo $query | cut -d " " -f 3)
arg4=$(echo $query | cut -d " " -f 4)

url="https://www.domain.com/$arg1/$arg2/$arg3/$arg4/"
 
open "$url"

Now in my particular case, I would like that if the value of $arg4 is, for example, "vws", it be automatically replaced with "video-with-sound", and then url would open with that full value.

The goal is for me to be able to use shortcuts when the values would be very intricate to type out.


Is that something that would be doable? I would greatly appreciate some help and/or guidance.

 

Thank you very much in advance!

Link to comment

Welcome @Mafraja. This should work.

arg1="$(cut -d ' ' -f 1 <<< "${query}")"
arg2="$(cut -d ' ' -f 2 <<< "${query}")"
arg3="$(cut -d ' ' -f 3 <<< "${query}")"
arg4="$(cut -d ' ' -f 4 <<< "${query}")"

[[ "${arg4}" == 'vws' ]] && arg4='video-with-sound'

open "https://www.domain.com/${arg1}/${arg2}/${arg3}/${arg4}/"

But next time, please post the actual Workflow you’re working on. We can’t properly help you without access to it.


Read the Reporting Problems with Workflows topic, as it gives a nice overview on how to build an effective report.

Edited by vitor
Link to comment

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...