Jump to content

App-specific snippets

Recommended Posts

I came across instructions for creating a workflow that would allow me to create snippets that only work in specified apps (referenced in this thread and explained further in this blog post). It involves using the Snippet function in a workflow, activating the "used focused app variable" option, and naming that variable "app." The blog poster used a script to specify the apps for the "app" variable (the apps in which the snippet applies). I've pasted that script below. However, I'm having a hard time getting it to work. In particular, I cannot seem to identify the right app (or really any app--the current version doesn't work for me, either). Does anyone have any suggestions? (Fwiw, I am trying to identify the Obsidian and Ulysses applications). I am using Mac Sonoma 14.3 and Ventura 13.6.3, as well as Alfred 5.5.


var map = {
  'com.google.Chrome': 'Hello Chrome',
  'com.microsoft.VSCode': 'Hello Code',
function run(argv) {
  var app = $.getenv('app')
  return map[app]


Screenshot 2024-03-19 at 7.03.49 AM.png

Link to comment

Thanks! I'm pretty sure I understand the basics in the starting guide. I was confused, though, about what happens with the "Focused app variable" in the Snippet Trigger (the description of the variable as "with" the bundle id made me think I had to specify the bundle id upfront, and that wasn't working). But now I realize that I need, within the Snippet Trigger configuration, to just name the variable something and then (I think) match the variable to the specific bundle id within the Conditional Utility.  


So I have set up the workflow as follows: 

1. A Snippet Trigger with "focused app variable" checked and named "app."

2. A three-way Conditional Utility as shown in the attached screenshot. 

3. Three Copy to Clipboards, two that paste specific content into the frontmost app and a final one that pastes the snippet trigger itself (I don't want the snippet to be transformed in other apps). 


However, this doesn't seem to work. In Obsidian and Ulysses, typing the trigger just gives me the trigger itself (that is, the Conditional Utility is somehow bumping me into the "else" track (I've tested to be sure)). I'm pretty sure these are the bundle ids for these apps (I've used a workflow to determine them), though. Is it apparent what I'm doing wrong?

Screenshot 2024-03-23 at 11.59.14 AM.png

Link to comment

Wonderful, thanks a lot, @vitor! I also switched "is equal to" to "matches regex" and then everything worked. In case anyone finds it helpful, the final Conditional Utility looks like: 


if {var:app} matches regex obsidian then...

if {var:app} matches regex com.ulyssesapp.mac then...



And I think actually my workflow was kicking out the wrong bundle ids after all. I used this great workflow by Alan He instead to find the right ones. 


I should note that this snippet trigger ends up having a slight (split-second but noticeable) lag, in case it's relevant to anyone else. 



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