Jump to content

Script Filter JSON - example use of the "action" key?


Recommended Posts

Posted (edited)

I was re-reading https://www.alfredapp.com/help/workflows/inputs/script-filter/json/ today checking for recent changes that were introduced in 5.5. I noticed that there's an "action" key (apparently not new...) that can be used to customize the behavior when used with Universal Actions. I might be having a "slow brain" day, but I can't quite wrap my head around how this works or when it would be useful. 

 

Anyone got any examples (real world or hypothetical) of this feature?

 

image.thumb.png.8b84c5d144b6c3810206a7ee49b8a6ee.png

 

Edited by luckman212
Posted

Real example. Download Media, after downloading the file, writes the origin URL to its metadata. When listing such a file in Watch List, calling the Universal Action will either act on the file itself or its origin URL, depending on the Workflow’s configuration. action is used to control that dynamic nature.

Posted

Thanks @vitor I had a play and think I grasp it now. So when actioning an item via <TAB> key from a Script filter, the "action": { ... } will override the value passed into the remainder of the workflow, overriding the arg key. And, some detection is done to see if it's text, file(s) or url. Is this correct?

 

Still unclear to me whether it makes sense to have multiple types defined e.g.

 

"action": {
  "text": "one",
  "auto": "two"
}

 

In that case, if the arg was a string abc would the output be one or two

 

Is there a way to determine which format was autodetected further downstream in the script via some variable?

Posted
18 hours ago, luckman212 said:

the "action": { ... } will override the value passed into the remainder of the workflow, overriding the arg key.

 

18 hours ago, luckman212 said:

Is there a way to determine which format was autodetected further downstream in the script via some variable?

 

Once you enter the Universal Actions panel, you’re effectively leaving the workflow and triggering something else, so there is nothing further downstream on that run.

 

18 hours ago, luckman212 said:

Still unclear to me whether it makes sense to have multiple types

 

It might. Depends on what your Universal Actions take as input.

 

18 hours ago, luckman212 said:

In that case, if the arg was a string abc would the output be one or two

 

Both. You can see them in the Universal Action preview after tabbing.

Posted (edited)

Another question @vitor if you have a moment.

I noticed that if an item has an empty arg then the action: {...} seems to be ignored, and the Universal Action cannot be invoked for that item. This is causing a minor problem for one of my workflows, because I actually DO want the user to be able to invoke the UniversalAction, but also if they simply hit [ENTER] to action the item, I do not want any argument passed into the next step.

 

Example (Script Filter)

 

cat <<EOJ
{ "items": [
  { "title": "Fruit",
    "arg": "Apple",
    "subtitle": "arg='Apple' ua='Orange'",
    "action": {
      "auto": "Orange"
    }
  },
  { "title": "Folder",
    "arg": "~/Documents",
    "subtitle": "arg='~/Documents' ua='~/Desktop'",
    "action": {
      "file": "~/Desktop"
    }
  },
  { "title": "URL",
    "arg": "https://www.alfredapp.com/help/workflows/inputs/script-filter/json/",
    "subtitle": "arg='Alfred JSON help' ua='https://alfredapp.com'",
    "action": {
      "url": "https://alfredapp.com"
    }
  },
  { "title": "Thing with no arg",
    "arg": "",
    "subtitle": "arg='' ua='~/Documents'",
    "action": {
      "file": "~/Documents"
    }
  },
]}
EOJ

 

screenshot_c9RzX3wR.thumb.png.7172e66e366f80bdf2090875aacf41eb.png

Edited by luckman212

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