How to get output from a Shorctuts app shortcut?

I'm trying to create a menu item that runs a shortcut. I've figured out how to assign the button to run the shortcut, I just don't know how to get the shortcut's output. The shortcut is configured to output its result:

For example, if I wanted to add the output to the clipboard or transform it with javascript, what is the next step?

Thank you

You would need to use scripting for that.

So basically you'd use the predefined action "Run Real Java Script" with a script like this:

async function someJavaScriptFunction() {
  let shortcut = "some name";
  let input = "some input"; // optional
  let result = await runAppleShortcut({name: shortcut, input: input});
  // example transform
  result = result.toUpperCase()
  // paste the transformed text?
  await paste_text({text: result})
  return result;
}

https://docs.folivora.ai/docs/1106_java_script.html#4-running-shortcuts-from-apples-shortcuts-app

Maybe describe an exact example usecase then I can post a script for it

1 Like

Ah! Ok. Thank you, @Andreas_Hegenberg. I'll give that a try.

Just for reference, starting with the latest BTT version 5.195 the last shortcuts result is also automatically stored in this variable:

BTTLastShortcutResult
1 Like

I'm running 5.252 and BTTLastShortcutResult is null even though I run my named trigger that runs an Apple Shortcut that returns an xml.

[
  {
    "BTTActionCategory" : 0,
    "BTTLastUpdatedAt" : 1741252368.6211429,
    "BTTTriggerType" : 643,
    "BTTTriggerTypeDescriptionReadOnly" : "Named Trigger: Bluesound Volume Up",
    "BTTTriggerTypeDescription" : "Bluesound Volume Up",
    "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
    "BTTUUID" : "F9183AE8-5A31-49B2-B8C7-88FF06908F22",
    "BTTPredefinedActionType" : 295,
    "BTTPredefinedActionName" : "Run Shortcut from Shortcuts App",
    "BTTGenericActionConfig" : "Blue Up",
    "BTTTriggerName" : "Bluesound Volume Up",
    "BTTEnabled" : 1,
    "BTTEnabled2" : 1,
    "BTTOrder" : 3,
    "BTTAdditionalActions" : [
      {
        "BTTActionCategory" : 0,
        "BTTLastUpdatedAt" : 1741252115.8892469,
        "BTTTriggerParentUUID" : "F9183AE8-5A31-49B2-B8C7-88FF06908F22",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
        "BTTUUID" : "867DB851-5D6A-4FB5-A879-95858D0B7BCA",
        "BTTPredefinedActionType" : 254,
        "BTTPredefinedActionName" : "Show HUD Overlay",
        "BTTHUDActionConfiguration" : "{\"BTTActionHUDBlur\":true,\"BTTActionHUDBackground\":\"33.000000, 69.000000, 95.000000, 127.500000\",\"BTTActionHUDOffsetY\":40,\"BTTIconConfigImageHeight\":60,\"BTTActionHUDPosition\":5,\"BTTActionHUDDetail\":\"\",\"BTTActionHUDDuration\":0.89999997615814209,\"BTTActionHUDDisplayToUse\":2,\"BTTIconConfigSFSymbolName\":\"speaker.wave.3.fill\",\"BTTIconConfigImageWidth\":100,\"BTTActionHUDSlideDirection\":0,\"BTTActionHUDHideWhenOtherHUDAppears\":true,\"BTTActionHUDAttributedTitle\":\"{\\\\rtf1\\\\ansi\\\\ansicpg1252\\\\cocoartf2821\\n\\\\cocoatextscaling0\\\\cocoaplatform0{\\\\fonttbl\\\\f0\\\\fnil\\\\fcharset0 SFPro-Regular;}\\n{\\\\colortbl;\\\\red255\\\\green255\\\\blue255;\\\\red255\\\\green255\\\\blue255;}\\n{\\\\*\\\\expandedcolortbl;;\\\\cssrgb\\\\c100000\\\\c100000\\\\c100000;}\\n\\\\pard\\\\tx560\\\\tx1120\\\\tx1680\\\\tx2240\\\\tx2800\\\\tx3360\\\\tx3920\\\\tx4480\\\\tx5040\\\\tx5600\\\\tx6160\\\\tx6720\\\\pardirnatural\\\\qc\\\\partightenfactor0\\n\\n\\\\f0\\\\fs50 \\\\cf2 \\\\{BTTLastShortcutResult\\\\}}\",\"BTTActionHUDWidth\":200,\"BTTActionHUDBorderWidth\":0,\"BTTActionHUDTitle\":\"\",\"BTTIconConfigIconType\":2,\"BTTActionHUDHeight\":200}",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTOrder" : 0
      }
    ],
    "BTTGestureNotes" : "Bluesound Volume Up",
    "BTTTriggerConfig" : {
      "BTTTriggerRestrictions" : "Blue Louder"
    }
  }
]

Have you tried calling your shortcut from apple script to see whether it really returns something?

tell application "Shortcuts Events" to run shortcut named "yourshortcut"

I just tried here but the variable is filled correctly here

1 Like

Aah yes, I didn't return a value from Shortcut explicitly.