Jump to content

Conditional branch will not work... I'm missing something simple.


Recommended Posts

Posted (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

alfred.jpg

Edited by BCraftMath
Added Alfred version and debug
Posted

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

Posted

I think it's rather simpler to design the workflow like this:

 

CleanShot2025-01-06at15_56.52@2x.thumb.png.5f6455e6749a49c3102bac54782dba8f.png

 

The Input field now looks like this:

CleanShot2025-01-06at15_57.55@2x.png.1b9a757262520bb855821c0b54c8e8ee.png

 

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

Posted

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.

Posted
27 minutes ago, Stephen_C said:

I think it's rather simpler to design the workflow like this:

 

CleanShot2025-01-06at15_56.52@2x.thumb.png.5f6455e6749a49c3102bac54782dba8f.png

 

The Input field now looks like this:

CleanShot2025-01-06at15_57.55@2x.png.1b9a757262520bb855821c0b54c8e8ee.png

 

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!

Posted
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?

Posted

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

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

Posted (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 by Stephen_C
Posted
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!

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