Select from Contacts a List of People Based on Email Label Using AppleScript - email

Using AppleScript, how do I get a list of all people in the Contacts application who have at least one email address with a particular label?
I tried:
set peopleToCheck to every person where ((label of its email contains strContactEmailLabelHome))
Unfortunately, it returns an empty set. This can’t be correct because
set peopleToCheck to every person where ((label of its first email contains strContactEmailLabelHome))
Returns a set of one person.

property text item delimiters : linefeed
tell application id "com.apple.AddressBook"
-- Get the label of every email of every person
get label of people's emails as text
set labels to the result's text items
-- Remove duplicate items from the list of email labels
tell (a reference to the labels)
repeat length times
if string 1 = "" then set string 1 to 0
if string 1 is not in rest of strings then set end to string 1
set string 1 to 0
end repeat
set contents to strings
end tell
labels --> List of unique labels currently in use by at least one contact
-- Choose a label to match contacts against
set [specificLabel] to choose from list of labels ¬
with title ["Search Contacts by Email Label"] ¬
with prompt ["Select one of your email labels:"] ¬
OK button name ["Search"] cancel button name ["Close"] ¬
without multiple selections allowed and empty selection allowed
-- Matches
set P to a reference to (every person ¬
whose emails's label contains ¬
the specificLabel)
-- Select the matching contacts in the application
set selection to P
return name of P
end tell

set customLabel to "customLabel"
tell application "Contacts"
return people whose label of emails contains customLabel
end tell
Or, using variable for the list:
set customLabel to "customLabel"
tell application "Contacts"
set theList to people whose label of emails contains customLabel
end tell
return theList

Related

Applescript service code to get value of a selected cell

I state that I am not a programmer and I have no experience with applescript. I have a "Numbers" file with some data in the "A" column. I want to select a value by clicking on it and thought I would run an applescript service to assign the selected value to a global variable and write the value stored in another cell in the sheet.
I found a similar script that seems to work in fact the value is stored in the variable but later the automator tells me that it cannot set the value read to the cell where I would like it to be compiled.
enter code here
on run {input, parameters}
global mybox
set mybox to 0
tell application "Numbers"
tell the front document to ¬
tell the active sheet to ¬
set CurrentTable to the first table whose class of selection range is range
tell the CurrentTable to get the value of the first cell in the selection range
if the result is not missing value then set mybox to result
display dialog "Cell value: " & mybox
set the value of cell "b2" to mybox
end tell
return input
end run
And, no need some service to get value of selected cell in Numbers.app. Example:
tell application "Numbers" to tell document 1 to tell active sheet to ¬
tell table 1 to set globalVariable to formatted value of ¬
item 1 of (cells of (get selection range))
NOTE. You can embed this script in the automator service, but it will make things slower, and doesn't make sense.

Cell to textbox and back with only email addresses

I have a spreadsheet where Column M contains a header in M1 and cells M2 - M22 contain email addresses that are later used to email the sheet as a .pdf. I have found the attached formula to ensure the column only contains email addresses, but I'm trying to adapt it. The user will click a command button to pull up a UserForm with 22 TextBoxes used to either change, add, or remove email addresses for the email to be sent, and then put the email addresses in the TextBoxes back into the cells on the worksheet. (The cells will be locked and can only be changed by the UserForm.) But I want to be able to either list the order of text boxes by inserting numbers 1-22 into the blank cells to show the user the order to use - to prevent blank cells - and then insert the TextBox values back into the cells only from TextBoxes with a valid email. Any ideas how to adapt this code, or does anyone have a better idea?
If Target.Column = 13 And Target.Value <> "" And Evaluate("COUNTIF(" & Target.Address & ",""*#*.*"")") <> 1 Then
Target.ClearContents
Target.Activate
MsgBox "Please enter a valid email address."
End If
End Sub```
Thank you in advance for any help!

Excel Form VBA Combobox reset

This should be easy but I can't seem to find anything to solve. I have a Form in Excel using VBA. The Excel sheet has four columns populated with data and the Form displays those fields.
The user then selects a value in a combobox, uses a command button to submit the responses and the values from the combobox are written to the Excel sheet.
The user then uses a command button to advance one row down in the spreadsheet and load the four values from a new row. This all works great.
The issue I am trying to solve is that the combobox remains selected to the value in the prior selection. I'd like to reset the combobox so nothing is selected and the user has to make a selection again for the next row.
Below is the code I am using to load the combobox and to set a variable for what the user selected. Can't seem to get the combobox back to it's default state after the user has submitted the form.
Private Sub cbDesAccWanted_Change()
Select Case cbDesAccWanted.Text
Case "Yes"
desacc = "Yes"
Case "No"
desacc = "No"
End Select
cbDesAccWanted.Text = desacc
End Sub
Private Sub cbDesAccWanted_DropButtonClick()
cbDesAccWanted.List = Array("Yes", "No")
End Sub
There are two ways to reset the combobox. Take your pick:
1
cbDesAccWanted.Value = Null
2
cbDesAccWanted.ListIndex = -1
the line
cbDesAccWanted.Text = desacc
is totally unnecessary.
Using cbDesAccWanted_DropButtonClick is not the right place to populate the list of values. This list should be set up when the form is first shown to the user.
(unelss the values it shows chnages in which case change it when the row changes or something, not when the user clicks on it)
So when theuser clicks the down arrow to move to thenext record include the following line
Me.cbDesAccWanted.text = Me.cbDesAccWanted.List(1)
Note (1) access teh 2nd item in the list which is No.
So this reset it to the default value of No.
Ok.

How implement Drop Down Lists in character interface?

I have two tables first its candidates and second this is employee. Before when i add new employee i have to look up in candidates table and after that take candidateID and add new employee with this key. I dont know how to look up in this candidate tabel. For now i have this but this is bad solution.
set cfname label "First #"
clname label "Last #" with overlay title "Candidate Name" 1 columns row 5 column 28.
find last candidates where firstname = cfname and lastname = clname no-lock no-error .
I want scrolling them and when i press "Enter" i take this key and add in employee table.
create employee no-error.
Assign
employee.candidateid = id
employee.employeeid = next-value(employee)
hiredate = today.
I dont know how to achive this.
As pointed out: this answers the orignal title of the question "How [to] implement Drop Down Lists in character interface?"
Something to get you started (character interface isn't really my best area so there might be easier ways).
It basically comes down to the VIEW-AS option on the variable definitions as well as some frame definitions.
DEFINE VARIABLE cTest AS CHARACTER NO-UNDO VIEW-AS COMBO-BOX LABEL "Select value".
DEFINE FRAME fr1
cTest WITH SIDE-LABELS 1 COLUMN.
cTest:LIST-ITEMS IN FRAME fr1 = "One,Two,Three,Four".
UPDATE cTest WITH FRAME fr1.

How to update another text box while typing in access 2007 form?

I have a few text boxes which have to be filled with numeric values from 0 to 100. Below them there is another text box which stands for a total (the sum of the values from the text boxes above). How can I update the sum text box while typing in any of the other text boxes above?
If you are happy that the sum box updates after a box is updated (enter, tab or such like is pressed), then this can be done without any code. First, you will need to set the format of the textboxes to be summed to numeric, then the control source of the sum box becomes:
=Nz([text0],0)+Nz([text2],0)+Nz([text4],0)+Nz([text6],0)+Nz([text8],0) ...
Note the use of Nz, it may be possible to eliminate this by setting the default value property of the various textboxes to be summed.
A large set of controls that need to be summed in this way is often an indication of an error in the design of the database. You would normally expect this kind of thing to be a separate recordset, which could more easily be summed.
I know this is old, but Google didn't come up with much for this topic and this thread didn't really help either. I was able to figure out a very easy way to do this, so hopefully anyone else looking for this will find this helpful.
My need was for actual text as opposed to numbers, but the same applies.
To do what the OP is asking for you'll need at least 3 textboxes. 1 is the textbox you want to have updated each time you type, 2 is the textbox you will be typing in, and 3 is a hidden textbox.
Set textbox 1 to reference the value of the hidden textbox 3 in its control source:
="something in my textbox " & [textbox3]
In the OnChange event of textbox 2 right a line that will set the value of the hidden textbox 3 to the Text property of textbox 2 that you are typing in:
Private Sub textbox2_Change()
Me.textbox3.Value = Me.textbox2.Text
End Sub
Each time the value of the hidden textbox 3 gets updated, the calculation/reference in the displayed textbox 1 will be updated. No need to save caret locations or anything else mentioned in this post.
I was able to do this in Access 2007 by using the On Lost Focus event of the text box.
Just put something like this on the On Lost focus event of each text box that you want to be added , just make sure to set the default value of each text box to 0.
Me.Totals.Value = Me.Text1.Value + Me.Text2.Value + etc..
The moment you click on the next text box or anywhere as long as it loses focus, your sum will already be on the Totals box. You may add as many text boxes as you like, just include them in the code.
This is problematic due to the asinine requirement in Access that you have to set focus to text areas before you can get their value. I would recommend you change your design so that the text field is updated in response to a button click instead of on change.
If you want to go the update-on-change route, you would attach change events to each of the addend text fields. The event handlers would need to save the caret position/selection length, update the sum in the output text field, and restore the caret position. You need to save/restore the caret position because this is lost when the focus changes.
Here's an example for two text fields (txt1 and txt2). The output field is named txtOutput.
Private Sub txt1_Change()
Dim caret_position As Variant
caret_position = Array(txt1.SelStart, txt1.SelLength)
UpdateSum
txt1.SetFocus
txt1.SelStart = caret_position(0)
txt1.SelLength = caret_position(1)
End Sub
Private Sub txt2_Change()
Dim caret_position As Variant
caret_position = Array(txt2.SelStart, txt2.SelLength)
UpdateSum
txt2.SetFocus
txt2.SelStart = caret_position(0)
txt2.SelLength = caret_position(1)
End Sub
Private Sub UpdateSum()
Dim sum As Variant
sum = CDec(0)
txt1.SetFocus
If IsNumeric(txt1.Text) Then
sum = sum + CDec(txt1.Text)
End If
txt2.SetFocus
If IsNumeric(txt2.Text) Then
sum = sum + CDec(txt2.Text)
End If
txtOutput.SetFocus
txtOutput.Text = sum
End Sub