How can I get a Shortcut's metadata (e.g., name) to use in a variable?

How do I get the name of a shortcut to use in a variable?

-  If `My Shortcut` has an action to run another shortcut 
	- Run `Helper` 
- How can I assign the name of the calling shortcut `My Shortcut` to a variable in `Helper`?
  • I don’t think there is a way to get the Name of the current shortcut and assign it to a variable…

    • Or is there ???

    • If I add a “native” Shortcuts Notification (not Toolbox Pro or Pushcuts)

      • The Shortcuts Notification shows the shortcut’s
        • Name
        • Icon
        • Color
  • Use case 1

    • I want to record when some shortcuts run in a log

      • Example: Check WiFi Connection
    • Log fields

      • Date
      • Time
      • Device Name
      • Shortcut Name
    • I have a shortcut Get Date & Device Name

      • Gets current date & time in a custom format
      • Gets device name
    • Check WiFi Connection will have an action to

      • Run Get Date & Device Name
      • I want Get Date & Device Name to get the Name of the calling shortcut
  • Use case 2

    • Use the shortcut’s name as the Title in a Toolbox Pro Notification similar to native notifcation

Thank you!

If shortcut FOO calls shortcut BAR, and BAR needs to know what it was called by, you could pass the text “FOO” from FOO to BAR via the shortcut input. It can contain multiple elements so you would not be foregoing adding other content.

Thanks!

I know I can do that, but…

  • It’s inefficient to hard code it
  • When I change the name, I’ll have to modify the shortcut
  • Especially, if I use this for more than a handful of shortucts

My current kluge hardcodes the name of the calling shortcut in the calling shortcut…

Thanks again!

Yes, but *if* there is no alternative than to manually enter or select it from a list each time, then I would argue that setting up a constant for a shortcut is the most efficient option.*

Unless I’ve missed something, which I might have done, you can only query the set of all on device Shortcuts and not the currently executing shortcut, which is what you would ideally do for your scenario and then grab the name property of that to pass to the next executing shortcut.

* Now you will find that it is possible to update shortcuts to an extent programmatically, so in theory you could build a shortcut capable of adding the name for you if you needed to do this at scale or frequently change your shortcut names.

Stephen,

  • Thank you for taking the time to share your expertise! I am an intermediate-level coder, and appreciate your thoughts.

    • btw: I started using Drafts last summer, and I have been using your actions, and they have been great learning examples and starting points for actions I’ve created.
  • That’s a great point. I was hoping someone had figured out an alternative.

  • I was trying to work around the limitation of not being able to query the currently executing shortcut during runtime:

    • By running a 2nd shortcut [inside the original one], could the 2nd shortcut identify / reference the original one that called it? :thinking:

    • The 2nd shortcut is not at the end of the original calling one.

      • After the 2nd shortcut runs, the original shortcut continues.
  • How would one update shortcuts programmatically?

Thank you again!
Sharon

:slight_smile: Glad you’re getting some use out of them and that you’re building your own. The power in Drafts is definitely around customising it to your own needs.

There are several shortcuts that have surfaced over the last few years that make changes. This one is probably as good a starting point for you to pick apart/re-use as any.

https://routinehub.co/shortcut/3724/

I would just note that you should always have good backups before messing with your shortcuts.

MergeCuts looks like a great tool to add to my tool box!

I have been writing separate helper shortcuts that can get called by different ones.
I just recently downloaded MFC Deck and have started experimenting with that to run a batch of different shortcuts.

I did learn the hard way to make backups :woozy_face: [Based on past coding experience, I should have known better!]. Thank you for the reminder!

  • Now I use the Save Backups shortcut from MacStories [I’m going to experiment with using MFC Deck to run that on a regular schedule].

  • I’ve also been duplicating a shortcut before I make changes so I have a “jic” [just-in-case] copy. I’ve been doing this for other things, so I just extended the practice to shortcuts.

Thanks again!! :smiley:

@AgentChange, you might find BART useful for backup, archive, and restore tasks. The embedded Help (section Shortcut Automation) discusses automating the backup and archive processes.

1 Like