Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kkclstuff

macrumors 6502
Original poster
Apr 18, 2015
312
206
NYC
hi does Shortcuts scripting recognize negative integers?

Im trying to trigger an 'if statement' with a calculated result:

if >0, say A
if 0, say B
if <0, say C

in my shortcut:
before 0, I get A.
at 0, I get B.
but after 0 (less than -1, -2, etc), I get A again. (instead of C). X
 
Last edited:

kkclstuff

macrumors 6502
Original poster
Apr 18, 2015
312
206
NYC
OK, so I solved my scripting issue by using an 'if statement' that is either >0 'A' or 0 'B', anything else would result in 'C'

BUT still curious about an answer to negative integers ;)


fullsizeoutput_283.jpeg

fullsizeoutput_282.jpeg

fullsizeoutput_281.jpeg
 

Jessica Lares

macrumors G3
Oct 31, 2009
9,612
1,057
Near Dallas, Texas, USA
Yeah, it supports negative integers. It's just you're using two plain numbers in math, so you're saying 90 - 3, and basically the negative number cancels out the subtraction and it becomes addition and so you get 93.

There is the adjust date action that you would do the comparison on with the if with one of the two dates and use the 90 days difference there.
 
  • Like
Reactions: kkclstuff

kkclstuff

macrumors 6502
Original poster
Apr 18, 2015
312
206
NYC
I see a format for dates "How long ago/Until" is this what you're referring to? I m not clear on how those formats work within different variables.
 
Last edited:

Jessica Lares

macrumors G3
Oct 31, 2009
9,612
1,057
Near Dallas, Texas, USA
I see a format for dates "How long ago/Until" is this what your referring to? I m not clear on how those formats work within different variables.

There's an action called Adjust Date that you need to use instead of Math. Math just sees the input as a number.

How long ago/Until is related to the current date, it's going to give you text like "3 months ago".

In adjusted date it's,

Subtract 90 days from 5/25 - Current Date

Then it's,

if adjusted date is before 5/25, this
if adjusted date is 5/25, this
if adjusted date is after 5/25, this

Add the date as a separate action and when you first use it rename it so it's more readable (you can do this with just the shortcut input too).

IMG_0484.PNG


It's going to give you the actual date, so you'd use the get time between if you wanted it to announce the amount of days left in the 'if date is before'.
 
  • Like
Reactions: kkclstuff

kkclstuff

macrumors 6502
Original poster
Apr 18, 2015
312
206
NYC
nice, I think scripting is gonna be my 2021 guilty pleasure. so many possibilities ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.