How do I use a variable value in an IF condition

Share your macOS, iOS, and iPadOS shortcuts here. Post your shortcut in a new topic and be sure to describe thoroughly (screenshots, full text of any scripts, apps used, etc).
CliveS
Posts: 858
Joined: Sun Jan 10, 2016 5:31 am
Location: Medomsley, County Durham, UK

How do I use a variable value in an IF condition

Post by CliveS »

[MODERATOR NOTE]: this post was initially posted on the topic referencing an example shortcut to get a variable. I've split it into a separate topic because it goes beyond the scope of what that example plugin does, but is a perfectly valid question.
---------------------------------
Just tried your demo and decided to use the get a variable bit in a shortcut to open the front door using a loop to re-trigger the lock as it locks after 10 seconds and sometimes it would be helpful to extend the opening by a re-trigger, but stop once the front door contact sensor opens.

I get the variable but the shortcut ‘If’ statement only gives ‘does not have any value’ or ‘does have a value’ as options and sending nothing to blank the Indigo variable is seen as ‘false’ so it always triggers as ‘does have a value’.

Is their another way to get this working?
CliveS

Indigo 2024.2.1 : macOS Sequoia 15.6.1 : Mac Mini M2 : 8‑core CPU and 10‑core GPU : 8 GB : 256GB SSD

The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer
User avatar
jay (support)
Site Admin
Posts: 19202
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: Variable Copy Demonstration shortcut

Post by jay (support) »

You need to post a screenshot of your shortcut (or at least the section that gets the variable and attempts to do the IF) in order for use to help.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
CliveS
Posts: 858
Joined: Sun Jan 10, 2016 5:31 am
Location: Medomsley, County Durham, UK

Re: How do I use a variable value in an IF condition

Post by CliveS »

Screenshot as requested
The variable was blank at this time (- no value - )
Shortcut.png
Shortcut.png (356.56 KiB) Viewed 1399 times
CliveS

Indigo 2024.2.1 : macOS Sequoia 15.6.1 : Mac Mini M2 : 8‑core CPU and 10‑core GPU : 8 GB : 256GB SSD

The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer
User avatar
jay (support)
Site Admin
Posts: 19202
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: How do I use a variable value in an IF condition

Post by jay (support) »

Hi Clive, after rereading your post I gave it a try. And spent the next hour trying to figure out what the heck is up with the IF statement.

I've posted another example plugin that shows you how to use the variable value in an IF statement.
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
CliveS
Posts: 858
Joined: Sun Jan 10, 2016 5:31 am
Location: Medomsley, County Durham, UK

Re: How do I use a variable value in an IF condition

Post by CliveS »

Thank you Jay, it makes me feel a bit better that it took you an hour to find a way around Apples roadblocks :)
CliveS

Indigo 2024.2.1 : macOS Sequoia 15.6.1 : Mac Mini M2 : 8‑core CPU and 10‑core GPU : 8 GB : 256GB SSD

The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer
Post Reply

Return to “Apple Shortcuts”