I am using AppleScript to search through a bunch of my contacts, with a specific (custom) property.
Here is my code:
tell application "Address Book"
set allPeople to every person whose last name = "CERTAIN_LAST_NAME"
get properties of item 1 of allPeople
end tell
The specific last name is just a person who I knew had that specific property.
And the (trimmed) output:
CATEGORIES:Contacts
UID:{MY_EMAIL_ADDRESS}:426
X-ABUID:SOME_ID_TAG:ABPerson
END:VCARD
I want to find everyone who contains the property UID with the value of {MY_EMAIL_ADDRESS}:some_number. I'm very new to OS X and AppleScript to so I'm not really sure what to do. I searched for a way to filter my contacts based on a custom property, with:
tell application "Address Book"
set allPeople to every person whose UID = "{MY_EMAIL_ADDRESS}:426"
get properties of item 1 of allPeople
end tell
But this gave me this error:
my_script.scpt:69:72: execution error: The variable UID is not defined. (-2753)
I appreciate any help with this issue!
The reason you can’t find UID is because it doesn’t exist as a field, even in your data. If you look at the bottom of the snippet you provided, it says “END:VCARD”. If you look up through the snipped text, you should see “vcard:"BEGIN:VCARD”.
The field that contains this text is vcard, and you can search through that.
tell application "Address Book"
set allPeople to every person whose vcard contains "UID:{YOUR_EMAIL_ADDRESS}:426"
get properties of item 1 of allPeople
end tell
I don’t have your values, of course, but I was able to do a search on cards that contained known values of UID in my own contacts.
Related
As part of an automation workflow I'd like to be able to store a reference to an applescript object inside an NSMutableDictionary. This is done, in effect, to be able to use variable variable names. Keeping an NSAppleScript instance alive, I'd then be able to refer back to previous results and continue from where I left off.
Concretely, I'd like to store a Presentation object (Microsoft PowerPoint) inside an NSMutableDictionary.
use framework "Foundation"
property memory : null
set memory to current application's NSMutableDictionary's dictionary()
-- function to get a ref to a presentation based on either a NAME or a PATH
on getPresentation(desc)
tell application "Microsoft PowerPoint"
if (item 1 of desc) is "" then
return item 1 of (get presentations whose path is (item 2 of desc))
else
return item 1 of (get presentations whose name is (item 1 of desc))
end if
end tell
end getPresentation
-- Fetch a currently open presentation (just an example)
-- this exists if you open a new presentation in PPT (no saving) and enter as title test
set pres to getPresentation({"test [Autosaved]", null})
memory's setObject:pres forKey:"presentation"
This throws the following error:
error "Can’t make «class pptP» 2 of application \"Microsoft PowerPoint\" into the expected type." number -1700 from «class pptP» 2
I'd like to be able to store the object pres for future use, refering to it from the containing Objective-C code (through NSAppleScript, calling methods on pres through wrappers as needed). I can tell the applescript to store the result of some handler at some address and use it later on.
I've tried using a reference to pres to solve the issue, but no luck.
Is there a way to solve this? Perhaps a wrapping class around pres that allows it to be stored inside the NSMutableDictionary? Perhaps I can roll my own Objective-C code that would work on pres?
Any help would be much appreciated!
AppleScript’s reference type is not bridged to ObjC so cannot cross the bridge directly. You can wrap it in a script object (as long as that object inherits from NSObject) and pass that over, though in past experience I found creating and using large numbers of bridged script objects also causes ASOC to crash.
Easiest solution is to keep AS references on the AS side, and store them a native data structure such as a key-value list, binary tree, or hash list. (e.g. My old Objects library provides reasonably fast DictionaryCollection (hash list) objects created for exactly this reason.)
I'm creating an installation with instalshield.
In the "Installation Interview", (which is part of the "Project Assistant") I set the option "to prompt users to enter their Company Name".
My question is: how can I interact with the value they entered? I mean how can I get it? I need to take this value and insert it to my app config file , during the installation process.
In a more general way, I would love to know how can I add text fields of my own and interact with the values the customers insert?
Thank you,
Noam
Look at the installation Wizard Noam. Anywhere you see an edit control, you will notice that it has a property associated with it. The property is a 'variable' that will have a value assigned to it. You can use the property to populate a registry, an XML file, etc.
I would look through the help documentation for InstallShield relating to Properties.
http://helpnet.flexerasoftware.com/isxhelp19/helplibrary/IHelpISXPropertiesUse.htm
The link above goes over the difference between Public and Private properties and how you can use them.
Ok, so I sort of solved it, I didn't use any built in dialog boxes, but simply created my own public property and dialog, then added an event to dialog and finally read the property value with powershell script, in more details (for future noobies) :
Create new property in Property Manager (under "Behavior and Logic"), give it a name and default value.
Create new dialog (under "User Interface").
At the behavior section of your dialog go to "Next" control (for example).
Add event (by pressing the tiny green plus sign at the line of the "Events")
Choose "SetProperty"
At the SetProperty line you can specify a condition, for example ApplicationUsers = "AllUsers"
At the "Property" field enter the property name (from first instruction)
At the "Value" field enter the value you wish for.
For getting the property value from powershell, create powershell script with the following: $value = Get-Property -Name PROPERTY_NAME
That's it.
This is not exactly what I asked for in the question but I believe this answer is more general and so also contains the answer to my original question.
In my scriptable app, one of the properties is of a named record type, and that record type has been declared in the sdef as well (named "custom record").
I can get the record like this:
get owner of anElement
--> {pool:"test", position:2}
I can also successfully test for it like this:
set target to {pool:"test", position:2}
if owner of anElement = target then
-- found!
But I cannot use it in a whose clause:
get allElements whose owner = target
--> {}
I also cannot use missing value in the test:
get allElements whose owner = missing value
--> error number -1700 from missing value to custom record
Is that expected behavior with AppleScript, i.e. is it unable to handle records in whose clauses?
Or am I doing something wrong? I have so far not implemented any coercion handlers nor special record handlers because nothing has indicated that I'd need them.
Also, please see my related question: Cocoa Scripting: Returning "null" vs. "missing value"
Short answer : It's expected behavior.
The whose clause works only for element reference types (classes which have an object specifier), but not for record types and custom lists.
Even the selection property of the Finder cannot be filtered by a whose clause.
I wanted to count no. of objects on Google homepage using static programming, i mean without creating object first(the way we do in dynamic one).
Pls tell me what is wrong in below statement
Set P = Browser("creationtime:=0").page("title:=Google").WebButton("type:=submit","html tag:=INPUT")
MsgBox P.Count()
Pls help, screenshot of error is attached here.
Thanks
You can get the total number of buttons by using descriptive approach.
Set odesc = description.Create()
odesc("micclass").value="WebButton"
Set i = Browser("creationtime:=0").Page("title:=Google").ChildObjects(odesc)
Msgbox i.Count()
Set i = Nothing : Set odesc = Nothing
You are actually trying to get a count of the child webbutton objects on that page object. With the original code that you posted, if there is more than one webbutton object on the page with the descriptors you're using, QTP will throw a multiple object matches found error.
Nelly's code regarding the description property is what you're after. If you are specifically looking for the count of all webbutton objects with a type:=submit, you can add additional description properties:
odesc("micclass").value="WebButton"
odesc("type").value="submit"
doing this will filter out buttons that don't have the matching type value
This is my current code:
tell application "System Events"
set accounts to get the properties of every user
end tell
This code will return the properties of all the accounts. How would I make Applescript check for a specific account name?
So lets say one name of an account is Bob. How would I check to see if one of the account names is Bob?
Named objects, including users, can be mentioned by name: type "Name". So, to check if a user "Bob" existed, you could use the expression exists user "Bob" in a block addressed at System Events. Or, to get the properties of such a user, given that one existed, you could:
tell application "System Events" to get the properties of user "Bob"