AppleScript Error -1700 when trying to access Apple Reminders - list

I get an AppleScript script error with the following and would be very grateful if someone could explain why.
In Apple's Reminders application, I have created a simple list with four reminder items, named as follows:
      List Name:   Colours
     Reminders:   Red, Yellow, Light Green, Dark Green
In AppleScript, I've then set up this variable:
set lstMyList to {"Red", "Yellow", "Orange", "Blue"}
What I do not understand is the following, where the first two statements work but the third does not.
Statement 1. (succeeds)
This returns true, as the name of reminder 1 ("Red") is in lstMyList
tell application "Reminders"
return (name of reminder 1 of list "Colours") is in lstMyList
end tell
Statement 2. (succeeds)
This returns {"Light Green", "Dark Green"}
tell application "Reminders"
return (name of every reminder in list "Colours") whose name contains "Green"
end tell
Statement 3. (fails)
This should return {"Red", "Yellow"}, but instead triggers a -1700 error
tell application "Reminders"
return (name of every reminder in list "Colours") whose name is in lstMyList
end tell
The full error that pops up is:
"Reminders got an error: Can’t make {"Red", "Yellow", "Orange", "Blue"} into type specifier."
number -1700 from {"Red", "Yellow", "Orange", "Blue"} to specifier
I cannot understand what's happening in this third case, as the first statement uses "is in lstMyList" without any problem, and the second statement uses "whose" without any problem.
I should add that I'm aware that the error can be bypassed completely by turning the code around, e.g. looping through lstMyList and checking the reminders. However, I am trying to avoid such a solution because that would entail the repeated sending of Apple events, which would result in a marked increase in run time, especially with large numbers of list items.
Any explanations and/or advice here would be much appreciated. Thank you.

It's a matter of who you're talking to.
When you say
return (name of reminder 1 of list "Colours") is in lstMyList
two things happen.
First, an Apple event is sent fetching the name of reminder 1 of list "Colours". The work here is done by the Reminders app; the specifier name of reminder 1 of list "Colours" is a hierarchy that it can understand.
Second, internally (within this script), AppleScript-the-language takes the resulting string and checks the list for containment of that string.
When you say
return (name of every reminder in list "Colours") whose name contains "Green"
you are sending a single Apple event to Reminders and that's all you are doing. Nothing guarantees that Reminders is going to be willing to do this calculation for you, but it happens that it is willing. It works out the whole specifier and returns the result to you.
Similarly when you say
return (name of every reminder in list "Colours") whose name is in lstMyList
you are asking Reminders to do this as a single Apple event too. You are hoping that the is in lstMyList specifier is something that Reminders is willing to do. And it isn't. AppleScript is, but Reminders isn't. Containment in a list is just not a specifier Reminders does. You are sending this Apple event:
get «property pnam»
of every «class remi»
of «class list» "Colours"
whose {"Red", "Yellow", "Orange", "Blue"} contains «property pnam»
That Apple event is just too weird. You cannot know, without trying, what specifiers an application will respond to; it happens that Reminders doesn't like this one, and there's nothing you can do about it.
The way I would do this is to say
set lstMyList to {"Red", "Yellow", "Orange", "Blue"}
set output to {}
tell application "Reminders"
tell list "Colours"
set rems to (get every reminder)
set names to (get name of every reminder)
end tell
repeat with i from 1 to count of names
if item i of names is in lstMyList then
set end of output to item i of rems
end if
end repeat
end tell
We have now collected references to the correct reminders (in output), but we sent only two Apple events, which is cheap and fast. The rest of the work was done internally by AppleScript. And of course if you wanted only the names, not a reference to the actual reminder, you could do it with just one Apple event, to collect the names.

Related

Is there a way to check the value of the cell to the left and add two to the count, unless there is a value entered in another cell in the same row?

I am trying to write a piece of code in Google Sheets that automatically creates a follow-up date based on the date in the immediate left cell. It gets that date, and adds two (days) to it. Then that date gets pushed into Appsheet, where it is marked on a virtual calendar.
I also want the code to recognize when something is filled into the "Status" section (which is located in the 4th cell to the right) and fill in the current cell with something like "Done".
Currently, everything I have works except for that last part, when something is entered into the Status column I get an error that reads;
Function IF parameter 1 expects boolean values. But 'Declined' is a
text and cannot be coerced to a boolean.
I believe that means I need to convert the data in the status column into a boolean value, but I have no idea how to proceed in doing that. See below code;
=IF(INDIRECT("RC[4]",0), "Done", INDIRECT("RC[-1]",0) +2)
Let me know what you guys think, and thank you in advance for your help 👍
try:
=IF(INDIRECT("RC[4]",0)="Declined", "Done", INDIRECT("RC[-1]",0) +2)
or:
=IF(INDIRECT("RC[4]",0)<>"Declined", "Done", INDIRECT("RC[-1]",0) +2)

Report Builder- Nested If Statements with Multiple Values to Categorize

I am working in Report Builder and having issues creating a calculated field to categorize data from another column.
To simplify and explain my goal:
I’d like to create a calculated field with 4 distinct categories and I’m assuming the best way to do that is a nested if statement. Feel free to correct me if that is not the best function to use.
Category 1: Let’s just call it “A”
Category 2: “B“
Category 3: “C“
Category 4: “D”
Values from the other column:
Simplified Example-
Numbers 1-10 would be category A,
numbers 11-20 would be B,
numbers 21-30 would be C,
numbers 31-40 would be category D
However in my particular case the values aren’t nicely organized in those 10 consecutive ranges. For example, I have a 33 value that would be an A category, which makes it so I can’t use the greater than or less than operators.
Having explained my issue and goal- my question is how to write the syntax for an if statement when I have multiple discrete values that aren’t neatly organized in consecutive numerical order?
I hope this question makes sense.
I tried using just one argument to get it going and got stumped when it didn’t work:
Iif(field data = 1,2,3,4,5,6,7,8,9,10,33, “A”, “Other”)
It doesn’t work with the commas and I tried inserting the Or Operator between each value and that didn’t work either.
Thanks for any syntax tips you can provide.
There are a few ways you can do this.
Option 1: In your database design
The best way, in my opinion, is to do this in your database. Create a table with these values/category pairs and simply join to that whenever you need to include the categorised view of the data.
Option 2: In your report design
If you really have to do this in the report design, then using SWITCH() will probably be easier, certainly to read.
Given your second example, and expanding it a little you could do something like this...
=SWITCH(
(Fields!myData.Value >=1 AND Fields!myData.Value <=10) OR Fields!myData.Value = 33, "A",
(Fields!myData.Value >=11 AND Fields!myData.Value <=15) OR Fields!myData.Value = 34 OR Fields!myData.Value = 39, "B",
True, "Other"
)
SWITCH uses pairs of values, when the first value in the pair evaluates to true the seconds value in the pair is returned.
The final True, "Other" acts like an else. If not previous criteria matched, then the final pair always evaluates to true so "Other" would be returned.

Creating items from nested lists?

I'm working on making my program interact with an overarching framework that transfers information with lists.
I have a breed called 'people' and I export information about them with
to srti-lists
ask people [ foreach [self] of people [
set traits-list (list (who) (color) (heading)(xcor)(ycor)(shape)]]
set master-list [traits-list] of people
end
It works great for exporting that information. What I'm having trouble with is creating or updating people with information that I then receive in the form of a master-list.
I've been approaching it as probably a foreach problem, but the problem is that while that lets me execute commands for every item of the master-list, I haven't figured out how to then access the individual nested items.
So, say:
foreach master-list
[create person
set who item 0 master-list
etc. The problem is that syntax would create a person and then set the who as an entire sublist. Omitting the list throws up an error, and selecting the items more specifically is untenable since it'd be a list of variable length.
Any ideas how to iteratively select items from nested lists? Is foreach even the right approach?
I can't test it but this looks wrong to me:
to srti-lists
ask people [ foreach [self] of people [
set traits-list (list (who) (color) (heading)(xcor)(ycor)(shape)]]
set master-list [traits-list] of people
end
ask already loops through the people, so this looks like it is assigning to each turtle the list of traits for all turtles, and then the master-list is a list of those lists. You probably want:
to srti-lists
ask people [
set traits-list (list (who) (color) (heading)(xcor)(ycor)(shape)]
set master-list [traits-list] of people
end
On the setting of traits, the who number cannot be set - it is assigned automatically when the turtle is created and can never be changed. For example, try the following complete (broken) model and you will get an error:
to testme
create-turtles 5
ask one-of turtles [set who 10 ]
end
So I don't know what you mean when you say that who is assigned an entire sublist - who is always an integer and assigned sequentially.
Concerning your stated question - your syntax set who item 0 master-list would be find if you were trying to set a variable that you could actually set.

How can I resolve INDEX MATCH errors caused by discrepancies in the spelling of names across multiple data sources?

I've set up a Google Sheets workbook that synthesizes data from a few different sources via manual input, IMPORTHTML and IMPORTRANGE. Once the data is populated, I'm using INDEX MATCH to filter and compare the information and to RANK each data set.
Since I have multiple data inputs, I'm running into a persistent issue of names not being written exactly the same between sources, even though they're the same person. First names are the primary culprit (i.e. Mary Lou vs Marylou vs Mary-Lou vs Mary Louise) but some last names with special symbols (umlauts, accents, tildes) are also causing errors. When Sheets can't recognize a match, the INDEX MATCH and RANK functions both break down.
I'm wondering how to better unify the data automatically so my Sheet understands that each occurrence is actually the same person (or "value").
Since you can't edit the results of an IMPORTHTML directly, I've set up "helper columns" and used functions like TRIM and SPLIT to try and fix instances as I go, but it seems like there must be a simpler path.
It feels like IFS could work but I can't figure how to integrate it. Also thinking this may require a script, which I'm just beginning to study.
Here's a simplified example of what I'm trying to achieve and the corresponding errors: Sample Spreadsheet
The first tab is attempting to pull and RANK data from tabs 2 and 3. Sample formulas from the Summary tab, row 3 (Amelia Rose):
Cell B3: =INDEX('Q1 Sales'!B:B, MATCH(A3,'Q1 Sales'!A:A,0))
Cell C3: =RANK(B3,$B$2:B,1)
Cell D3: =INDEX('Q2 Sales'!B:B, MATCH(A3,'Q2 Sales'!A:A,0))
Cell E3: =RANK(D3,$D$2:D,1)
I'd be grateful for any insight on how to best index 'Q2Sales'!B3 as the correct value for 'Summary'!D3. Thanks in advance - the thoughtful answers on Stack Overflow have gotten me this far!
to counter every possible scenario do it like this:
=ARRAYFORMULA(IFERROR(VLOOKUP(LOWER(REGEXREPLACE(A2:A, "-|\s", )),
{REGEXEXTRACT(LOWER(REGEXREPLACE('Q2 Sales'!A2:A, "-|\s", )),
TEXTJOIN("|", 1, LOWER(REGEXREPLACE(A2:A, "-|\s", )))), 'Q2 Sales'!B2:B}, 2, 0)))

Watir selecting from a dynamically built search list

I am trying to select from a list of li elements that are dynamically aggregated based on search text as keys are entered. The list consistently comes up and some of the time the function correctly allows me to click on the list item and proceed. Other times it times out, early or late I can't tell. I have used sleep statements, inserted key presses, and other methods to get around this without any more success than this statement. Any ideas?
using Watir-classic
this is my seed text for my search function *
ie.text_field(:id, 'school_name').set "linc"
it returns with a list of schools that includes LINCOLN ADAMS ELEMENTARY *
ie.wait_until {ie.text.include? "ADAMS"}
ie.ul(:class, 'searchResults').li(:text => /ADAMS/).click
code without my comments in it
ie.text_field(:id, 'school_name').set "linc"
ie.wait_until {ie.text.include? "ADAMS"}
ie.ul(:class, 'searchResults').li(:text => /ADAMS/).click
puts "school selected"