How to pick out certain terms in Applescript? - applescript

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"

Related

Store AppleScript object in NSMutableDictionary

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.)

InstallShield: Get the organization name during installation

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.

Search a custom property

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.

Where does xcode 4 get the user name for file templates

When I create a new file in xcode, the file template emits the following line:
// Created by ANONYMOUS ANONYMOUS on 11/2/11.
According to the docs, this should be using the full user name of the currently logged in user, but it's substituting ANONYMOUS ANONYMOUS instead. Anyone know why it's not using my user name? The variable it's substituting for is ___FULLUSERNAME___
I think it pulls information for the "me" card in your AddressBook to replace the ___FULLUSERNAME___ and __MyCompanyName__ values. (In AddressBook.app "Card" menu, select "Go to My Card" and see if you have any data entered. You can set any card in your address book to be your "me" card and the basis for those values.)
I've also seen developers use the defaults command line tool to set those values explicitly rather than using the variables above when they wanted to swap details without changing their address book identity. For example when writing code on behalf of multiple companies.
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "My organization";}'
http://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeUserDefaultRef/100-Xcode_User_Defaults/UserDefaultRef.html#//apple_ref/doc/uid/TP40005535-CH3-SW10

Get short user name from full name

Anyone know how to get a user's short user name, eg. "johnsmith", given their full name, eg. "John Smith"?
Note I'm interested in any user, not the current user, so functions like NSUserName are irrelevant.
Why? I am authenticating a username and password using Authorization Services. This allows people to enter either their short name or their full name, which is nice, but I then need to know who they've actually logged in as (ie. short user name and/or user id).
Nasty hacks like [NSHomeDirectoryForUser(username) lastPathComponent] don't work consistently.
You need to use the Collaboration Framework :).
Link this framework to your project, and then you just need to do the following:
CBIdentity* identity = [CBIdentity identityWithName:#"John Smith" authority:[CBIdentityAuthority localIdentityAuthority]];
NSLog(#"Posix name: %#", [identity posixName]);
And voilà!
EDIT: If you need to find only users that are bound on the network, you need to use +managedIdentityAuthority instead of +localIdentityAuthority.
And if you need to find both local users AND network users, use +defaultIdentityAuthority.

Resources