Jump to content

Help me understand why the query won't pass through to this AppleScript

Recommended Posts

Hey guys,


I am having a tricky time getting my query to properly pass through to some AppleScript inside Alfred. I am using "{query}" as my placeholder, but I must be missing something more. I made a brief 3 minute video showing how I got here, and have uploaded the workflow here. Would love a bit of guidance if anyone has the resources to take a look.



Edited by Floating.Point
Removed "Solved" tag
Link to comment

Without testing, what’s likely going on is that you’re using "{query}" instead of {query}. You’re quoting it, meaning the text is being interpreted as a single element instead of the three you want.

And you don’t need the Arg and Vars Utility. You’ll get the same result by using Text as the Argument in the Hotkey.

Edited by vitor
Link to comment

Hi again,


So I am still tripping over using variables in my Alfred + AppleScript workflows. I feel like I'm getting it right, while clearly I'm not there yet. If anyone could help me comprehend my shortfall, I would be very grateful – I would love to understand how to do this properly.


My workflow is here

And a screen capture showing where I am at:



Edited by Floating.Point
Link to comment

There are a couple of problems I can see.


Firstly, you're setting your workflow variable incorrectly:




That's the raw value. Don't use quotation marks in there unless the value includes quotation marks.


The major problem is that AppleScript doesn’t let you use a variable in a tell clause the way you’re doing. The variable’s only available at runtime, but AS needs to know the name of the application before then at compile time to look up any app-specific terms you’re using (e.g. DoScript). AFAIK, there's no way to use app-specific terms in AppleScript without hardcoding the application name in the script somewhere.


You should either rewrite your script in JXA (where Application(someVar) works perfectly well) or insert the application name into the AppleScript some other way (i.e. “generate” the AppleScript).


Edited by deanishe
Link to comment

Hi deanishe,


Thank you so much for your wisdom here 😊


Before I move on to researching how to achieve the second part of your reply, would you mind staying with me for a moment - on the workflow variable? You mention that I shouldn't use quotation marks in a variable unless the value includes quotation marks…


If this was a working line of AppleScript, sans variable: 

tell application "Adobe After Effects 2021"


aren't those quote marks indeed part of the value if we use a variable instead?


Here is a sketch of how I am understanding this, would you mind pointing out where I am wrong?




Thank again, Nathan 😊

Edited by Floating.Point
Link to comment
3 hours ago, Floating.Point said:

would you mind staying with me for a moment - on the workflow variable?


It is the exact same principle (and mistake) of the previous case. You’re quoting too much.

When you tell application "Adobe After Effects 2021", the value does not contain quotes, it is enclosed by them. When you use AE, the code is substituting the value of the variable, not literally replacing the written text.

In other words, the quotes are delimiters which tell the code what is the value you want. They separate text from code. When in an Alfred utility (like Arg and Vars or the Workflow Environment Variables) you’re always writing text, never code → thus you don’t need quotes or delimiters → thus if you add them, Alfred thinks you want them literally.

If it makes it easier, just imagine those Alfred fields where you insert values already have quotes around them.

There is one thing which may still trip you up—your use of {query}. That does replace the text in your code literally. While useful in specific cases, it brings with it several disadvantages and is deprecated in favour of with input as argv. In your (initial) question, changing the code to support ARGV would require more effort than fixing your well-define case, so I refrained from mentioning it at the time to not sow confusion. In the future, though, you should default to it just like it is Alfred’s default.

Edited by vitor
Link to comment

Okay, this is coming together for me now. Thank you Vitor and deanishe for your time and patience.


When you use AE, the code is substituting the value of the variable, not literally replacing the written text

This is the crux of what is tripping me up. I can't thank you enough Vitor for first understanding my flawed interpretation and then guiding me through to how things actually work. Thanks again guys, I am on the right path again now!

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