BCraftMath Posted January 6 Posted January 6 (edited) Alfred 5.5.1 [2273] Basic workflow. Trying to trigger a prompt to enter text. If ok is pressed on the prompt then the branch should go to "Proceed" and if cancel is pressed, regardless of what is entered in prompt, then the branch should go to "End." In the branch, I have tried "CANCELLED" and CANCELLED, but it always resorts to Proceed, whether I click Ok or Cancel in the prompt. Workflow is here, just in case the pics don't help. https://drive.google.com/file/d/1XNpAlnxUAFgaU4Hiyerid9Mm6T6XlQMt/view?usp=drive_link The debug shows passing out 'CANCELLED ' to Post Notification as well as Conditional and Copy to Clipboard, but it always resorts to PROCEED branch of conditional. That is the problem I am facing. Debug: [10:47:16.968] Ok or Cancel[Keyword] Processing complete [10:47:16.973] Ok or Cancel[Keyword] Passing output '' to Run Script [10:47:19.419] STDERR: Ok or Cancel[Run Script] 2025-01-06 10:47:17.115 osascript[4626:227748] +[IMKClient subclass]: chose IMKClient_Modern 2025-01-06 10:47:17.141 osascript[4626:227748] +[IMKInputSession subclass]: chose IMKInputSession_Modern [10:47:19.425] Ok or Cancel[Run Script] Processing complete [10:47:19.429] Ok or Cancel[Run Script] Passing output 'CANCELLED ' to Post Notification [10:47:19.434] Ok or Cancel Processing complete [10:47:19.437] Ok or Cancel Passing output 'CANCELLED ' to Conditional [10:47:19.439] Ok or Cancel[Conditional] Processing complete [10:47:19.440] Ok or Cancel[Conditional] Passing output 'CANCELLED ' to Copy to Clipboard Edited January 6 by BCraftMath Added Alfred version and debug
vitor Posted January 6 Posted January 6 I can see two issues. 23 minutes ago, BCraftMath said: [10:47:19.437] Ok or Cancel Passing output 'CANCELLED ' to Conditional Do you see how the closing quote is on the next line? That’s because the text being sent isn’t really CANCELLED but CANCELLED\n (i.e. there is a newline at the end). Unfortunately, AppleScript and JXA always add the newline character when returning output. The easy solution is to use a Transform Utility to trim the whitespace. The second issue is that you’re using "CANCELLED" instead of CANCELLED in the Conditional. The quotes delimit your output in AppleScript, they’re not part of it (which is why they don’t show in the debugger).
Stephen_C Posted January 6 Posted January 6 I think it's rather simpler to design the workflow like this: The Input field now looks like this: You then use Alfred's Modifiers to provide the branching you want. However, note you cannot use Esc as a modifier as Alfred reserves that key. (I've just seen that Vitor has replied. Concentrate on his response: it will be better than mine! 😀) Stephen BCraftMath 1
vitor Posted January 6 Posted January 6 Actually, you just gave me another idea. For this specific workflow, a Dialog Conditional would work even better as it would do exactly the same but with zero code and fewer objects. Still, explaining why it wasn’t working provides the better learning opportunity to fix the understanding of the behaviour for future cases. Stephen_C 1
BCraftMath Posted January 6 Author Posted January 6 27 minutes ago, Stephen_C said: I think it's rather simpler to design the workflow like this: The Input field now looks like this: You then use Alfred's Modifiers to provide the branching you want. However, note you cannot use Esc as a modifier as Alfred reserves that key. (I've just seen that Vitor has replied. Concentrate on his response: it will be better than mine! 😀) Stephen I was using this, but sometimes the text got long and the use of other characters (specific math symbols, emojis, etc) would sometimes cause the alfred prompt to close depending on how I was interacting with other windows. I know my original post doesn't elaborate on my specific use case of why I would need this process in a workflow, but it does involving pasting equations and emojis within certain text fields, and then inserting those within some canned text. I just created this workflow for you all to test if needed. I hope that makes sense. Thanks for the recommendation though!
vitor Posted January 6 Posted January 6 1 minute ago, BCraftMath said: I just created this workflow for you all to test if needed. It was a fantastic and well explained test case, I’d even call it an exemplary request for help. Thank you for taking the time to make something so specific, it really shows you put in the effort to understand the issue and reduce it to its core components. I trust the explanation in the first post got you sorted? BCraftMath 1
Stephen_C Posted January 6 Posted January 6 I understand: thanks for the clarification. Just on the off-chance it could be useful you might take a look at my Save 'ur Note workflow (the link is to the workflow on the Alfred Gallery). I use Alfred's Text View as an option to allow the saving of paragraphs of text and you may find it useful to adopt something like that for your input (although I'm unsure the extent to which that view supports equations). Stephen BCraftMath 1
BCraftMath Posted January 6 Author Posted January 6 37 minutes ago, vitor said: I can see two issues. Do you see how the closing quote is on the next line? That’s because the text being sent isn’t really CANCELLED but CANCELLED\n (i.e. there is a newline at the end). Unfortunately, AppleScript and JXA always add the newline character when returning output. The easy solution is to use a Transform Utility to trim the whitespace. The second issue is that you’re using "CANCELLED" instead of CANCELLED in the Conditional. The quotes delimit your output in AppleScript, they’re not part of it (which is why they don’t show in the debugger). I tried two of your recommendations. 1. Transform definitely got rid of the whitespace and works like a charm now. Thank you for that. 2. The dialog conditional... does that take focus away from the front most app, preventing a direct paste into a text field? Regardless, the transform did the trick. I figured it had something to do with the extra space, but ChatGPT didn't recommend transform. Humans 1, AI 0. 😉 Thanks again.
Stephen_C Posted January 6 Posted January 6 (edited) 19 minutes ago, BCraftMath said: The dialog conditional... does that take focus away from the front most app, preventing a direct paste into a text field? I believe it does but you can work around the problem by using the Launch Apps & Files Action to bring the app window back to the front again (I hope I've correctly recalled the workaround!). Edit: Having checked, the workaround is in my Find and replace text workflow—and involved saving the app name as a variable in the early part of the workflow and then using the Open Apps Automation Task to make it active at the relevant time. Stephen Edited January 6 by Stephen_C BCraftMath 1
BCraftMath Posted January 6 Author Posted January 6 1 hour ago, Stephen_C said: I understand: thanks for the clarification. Just on the off-chance it could be useful you might take a look at my Save 'ur Note workflow (the link is to the workflow on the Alfred Gallery). I use Alfred's Text View as an option to allow the saving of paragraphs of text and you may find it useful to adopt something like that for your input (although I'm unsure the extent to which that view supports equations). Stephen Bookmarking your GitHub now to check out later. Thanks man!
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