Floating.Point Posted October 1, 2021 Share Posted October 1, 2021 (edited) 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 October 4, 2021 by Floating.Point Removed "Solved" tag Link to comment
vitor Posted October 1, 2021 Share Posted October 1, 2021 (edited) 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 October 1, 2021 by vitor Link to comment
Floating.Point Posted October 1, 2021 Author Share Posted October 1, 2021 (edited) Vitor, thank you. I proceeded as you suggested and it got me closer, then I tried disabling escaping double quotes and it worked! Thank you for your time and expertise, its very kind of you. Edited October 1, 2021 by Floating.Point Link to comment
vitor Posted October 1, 2021 Share Posted October 1, 2021 3 hours ago, Floating.Point said: Thank you for your time and expertise, its very kind of you. You have yourself to thank for an exemplary request for help. It was clear, polite, complete (provided the Workflow), and revealed effort. With reports like this, it’s a pleasure to try to help. giovanni and Floating.Point 2 Link to comment
Floating.Point Posted October 4, 2021 Author Share Posted October 4, 2021 (edited) 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 October 4, 2021 by Floating.Point Link to comment
deanishe Posted October 4, 2021 Share Posted October 4, 2021 (edited) 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 October 4, 2021 by deanishe Floating.Point 1 Link to comment
Floating.Point Posted October 4, 2021 Author Share Posted October 4, 2021 (edited) 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 October 4, 2021 by Floating.Point typo Link to comment
vitor Posted October 4, 2021 Share Posted October 4, 2021 (edited) 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 October 4, 2021 by vitor Floating.Point 1 Link to comment
deanishe Posted October 4, 2021 Share Posted October 4, 2021 7 hours ago, Floating.Point said: aren't those quote marks indeed part of the value if we use a variable instead? No. Quotes are used to insert string (text) literals into source code. Without quotes, it's not text, it's code, and the interpreter will try (and fail) to execute it. Floating.Point 1 Link to comment
Floating.Point Posted October 4, 2021 Author Share Posted October 4, 2021 Okay, this is coming together for me now. Thank you Vitor and deanishe for your time and patience. Quote 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! vitor 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now