Why can't I retrieve "contents" of a note item in Yojimbo, but I can retrieve the "content"? - syntax

A note item in Yojimbo's Applescript dictionary is defined as:
note item n [inh. database item] : A note item.
elements
contained by application.
properties
encrypted (boolean, r/o) : Is the note is encrypted?
contents (text) : The contents of the note. syn content
If this note is encrypted, the contents property is only readable
if permitted by the current security policies.
responds to
append, prepend.
In an attempt to export my data, I've been poking around with AppleScript, learning the language, etc, and currently have this:
tell application "Yojimbo"
repeat with EachNote in (note items in library)
display dialog (content of EachNote) as string
end repeat
end tell
What's confusing me is that, though the class defines the property "contents", I have to use "content" to retrieve the contents. Using "contents" results in this error:
Can’t make «class YNot» id "A0C9E19E-3106-44F9-97A6-A1A74AD77948"
of application "Yojimbo" into type string.
I'm assuming the "syn content" means it's a synonym, thus I should be able to use "content" and "contents" interchangeably. But apparently the synonym works, but the original does not...?
Also, more simply, why do the contents have to be coerced into a string? If I look at the properties on the object (via: (properties of EachNote) as string ), "contents" is a double-quoted string, though I realize this isn't necessarily "proof" that it's a string.
I'm still starting with AppleScript, so if I'm making a n00bish mistake, feel free to slap.

For others who find a similar confusion, I found help here: http://groups.google.com/group/yojimbo-talk/browse_thread/thread/d04f42db335c77e7
So all props go to Jim for being awesome!
The basics:
contents of an object is different than contents of a variable containing an object.
contents of a variable containing an object returns the object, not the object's contents, unlike every other property. Other properties return the property of the object in the variable, as expected.
This means, to get the contents of an object inside a variable, you need to use contents of contents of variable.
As demonstrated here, on my blog, yes, this is extremely strange. While var == var and var == contents of var, var != contents of (contents of var), so Applescript does indeed violate the identity principle for "contents" in this specific case. It does not chain this effect, though, so you shouldn't need to use contents of three layers deep (it'll work the same as two)
contents of contents of var works on objects as well, so it's always safe to use.
Many dictionaries use content as a synonym of contents, which avoids this whole problem. If desired, use content of var, and it'll work like other properties, always returning the object's content instead of the object.

Related

In Anylogic how do you extract the name of an object so i can use and assign it as a Text value? (Object >> Text)

The Problem: An agent has a parameter that refers to an object (lets say an INode). I want to get and use the name of that INode as plain text without writing a function that maps INodes to their names. If currentLocation (which has a value of Node12) is the parameter, in a snippet, it looks like:
agent.currentLocation
Is there a name property of Parameters or other Objects that i can reference and it returns a String (just the text "Node12" in this case)? I have tried all kinds of references with parameter.name, getValue, etc, to no avail.
For INodes you can use myNode.getName(), as you can for every object in Java.
However, you cannot get the name of parameters, variables, etc. And you shouldn't do that, it is considered bad practice :-)

Get Automator app result in external Applescript?

Is there a way to retrieve result of an Automator app script in an external Applescript app (not the Applescript lines in Automator)?
Something like:
tell application "My_Automator_App"
-- suppose My_Automator_App checks the Calendar to see if there some events today
-- "Show Result" in Automator will display a list
get the_Result -- list returned by Automator
end tell
I looked into this a little bit and didn't find a natural means by which AppleScript and Automator applets can communicate, although this doesn't mean one definitely doesn't exist.
In the meantime, you could implement one of a couple of workarounds/hacks that, although a little unseemly in their methods, do achieve the desired result without creating any side issues that would affect the functionality of an applet itself.
1. Use The Clipboard
Append a Copy to Clipboard action at the end of the applet's workflow, or following the action whose result you would wish to be reported.
Retrieving the clipboard from AppleScript is simple:
get the clipboard
This will probably suit return values that are simple text strings or a number. Passing an array of items from an Automator action to the clipboard isn't very reliable, sometimes only allowing access to the first item. However, this can be resolved with a small AppleScript within the workflow to process results arrays properly and convert them into an accessible format, e.g. a comma-delimited string.
However, the clipboard is also capable of storing image data, file references, and other data types, so it will be possible (if not always straightforward) to send those to be retrieved in an AppleScript.
Where possible, strings and numbers are the safest storage types.
2. Write Out To A Temporary File
To avoid using the clipboard as an intermediary, or if you wish the applet to report multiple variables without too much work, then writing the data to a temporary file is a fairly common practice, such as is done in shell scripts when persistant values are needed between multiple executions of the same script.
There's actually a special directory that gets periodically purged so that temporary data files don't accumulate: /tmp. It's hidden in Finder, but you can still create files and delete them as you would any other directory. Files that aren't access for 3 days get purged by the system.
There is a New Text File action that can write text to a file:
Specifying the /tmp directory is most easily done by creating a variable whose value is "/tmp" (without the quotes), and dragging that variable onto the appropriate field.
But my inclination would be to insert an AppleScript, or more suitably, a shell script into the workflow, with which file manipulation becomes easy and more capable.
Calendar Events Example
Using a similar example to the scenario you described, a simple applet that retrieves calendar events might have a workflow that looks like this:
where you can calibrate the first action to isolate the events you want, such as today's events. That action returns a type of object that isn't easily processed by AppleScript, but the second action extracts the relevant data in text format, summarising the list of events that the first action returned.
This is where a temporary file is useful to write out the data to a text file, which can then be retrieved in an AppleScript.
Given this Automator applet saved under the named "CalEvents", this AppleScript makes use of that applet and its result:
property tidEvents : [linefeed, linefeed, "EVENT", space] as text
property tidDetails : {tab, " to "}
property tid : a reference to my text item delimiters
run application id "com.apple.automator.CalEvents"
set tid's contents to tidEvents
set EventsSummary to read POSIX file "/tmp/EventsSummary.txt"
set EventsList to the EventsSummary's text items
set [[n], EventsList] to [it, rest] of EventsList
set n to n's last word as number
EventsList -- The final list of events from first to last
Upon its first run, the applet requires consent to access your calendar information, which only needs to be done once and will make the above script appear to fail. Once authorised, you can run the script as often as you like to get the most up-to-date content of the /tmp/EventsSummary.txt file.
Each item in the list variable EventsList is a block of text that looks like this (asterisks are my redactions for privacy, as are the address items in curly braces):
4 OF 8
Summary: GP Appointment
Status: none
Date: 07/12/2017 to 07/12/2017
Time: 14:45:00 to 15:45:00
Location: ******** Medical Centre
{Address Line 1}
{Address Line 2}
{County}
{Post Code}
United Kingdom
Notes: 01*** *****9
Each value is separated from the preceding colon by a tab character, which won't be obvious here. Also, as you can tell from the date format and address, these are British-formatted values, but yours will, of course, be whatever they are set as in Calendar.
But since each list item is much the same, extracting details for a particular event will be simple in AppleScript, first by splitting a particular event item into paragraphs, and then splitting a particular paragraph by either a tab or space character (or both) or some preposition that naturally delimits useful bits of text:
set |Event| to some item in the EventsList
set tid's contents to tidDetails
set EventDetails to {title:text item 2 of paragraph 2 ¬
, startTime:text item 2 of paragraph 5 ¬
, EndTime:text item 3 of paragraph 5} of the |Event|
which places the important event details, such as its name and start/end times, in an AppleScript record:
{title:"GP Appointment", startTime:"15:45:00", EndTime:"16:00:00"}

What are all of the possible Class Names in QTP or where can I find them?

I'm using QTP 11 and I could use a handy reference for all of the possible values for "Class Name". I'm not trying to manipulate this information. I just need a reference.
For example I know that I can access any input element using "WebEdit()" but what do I use for, say, a table cell.
I want a list I can refer to, not steps for finding the type of an object.
Three options come to mind immediately:
Option A. The handiest way to find the names probably is to look into the dialog Tools/Object Identification.
There, in the "Test Object classes" listview, you see all test object class names for the environment selected under "Environment" that QTP knows of.
Option B. If in the dialog from A. you push the "Generate script" button, creating a script. Use a grep facility (or TextPad, for that matter) to extract all lines containing the text "Object identification configuration for" from that script. This results in a text which after some cleanup is these lists:
User-defined (?):
"abtobjectgraphicswidget"
"cwarrowbutton"
"cwcheckbutton"
"cwlabel"
"cwpushbutton"
"cwradiobutton"
"cwtext"
"cwtext_multi"
"ewflowediconlist"
"ewiconarea"
"ewiconlist"
"ewicontree"
"ewpmnotebook"
"ewspinbutton"
"ewtablelist"
"ewtabletree"
"ewwinnotebook"
"gxcombobox"
"gxedit"
"gxlistbox"
"listview20wndclass"
"listviewwndclass"
"msvb_lib_toolbar"
"richedit"
"seccustomtoolbar"
"secmenubar"
"sectabctrl"
"sectabwnd"
"sectreectrl"
"sectreeview"
"stgrid"
"sysdatetimepick32"
"sysmonthcal32"
"textedit"
"treeview20wndclass"
"treeviewwndclass"
Standard (?):
"activex"
"acxbutton"
"acxcalendar"
"acxcheckbox"
"acxcombobox"
"acxedit"
"acxradiobutton"
"acxtable"
"javaapplet"
"javabutton"
"javacalendar"
"javacheckbox"
"javadialog"
"javaedit"
"javaexpandbar"
"javainternalframe"
"javalink"
"javalist"
"javamenu"
"javaobject"
"javaradiobutton"
"javaslider"
"javaspin"
"javastatictext"
"javatab"
"javatable"
"javatoolbar"
"javatree"
"javawindow"
"dialog"
"static"
"winbutton"
"wincalendar"
"wincheckbox"
"wincombobox"
"window"
"winedit"
"wineditor"
"winlist"
"winlistview"
"winmenu"
"winobject"
"winradiobutton"
"winradiogroup"
"winscrollbar"
"winspin"
"winstatusbar"
"wintab"
"wintable"
"wintoolbar"
"wintreeview"
"browser"
"frame"
"image"
"link"
"page"
"viewlink"
"webarea"
"webbutton"
"webcheckbox"
"webedit"
"webelement"
"webfile"
"weblist"
"webradiogroup"
"webtable"
Note 1: the user-defined objects are probably add-on specific, or otherwise registered in a special way in QTP.
Note 2: this is just a sample of what you might get on your machine. For example, I don´t have the Delphi add-on active, so all the Delphi control´s test object class names are missing. If you want me to activate all add-ons, and re-create this list, I´ll give you my bank account first ;)
Option C. In the online help, from the contents, try navigating to the "HP QuickTest Professional Object Model Reference". It contains chapters per environment, and most of them consist of "X Object" chapters, i.e. there is a "WebButton Object" chapter under "Web".
Option D. See Rich's answer :-O
Since micclass is the same thing as the Class Name property (other than programming placement), the class names of the objects that you are trying to apply to micclass can be utilized. To find the class names of all objects used in the QTP environment, you can use the Mercury.ObjectRepositoryUtil to iterate through the objects and collect what's necessary for the micclass.
More details on that -> Here and Here

VS2010 save array/collection data to a file while debugging

Is there some way to save array/list/collection data to a file while debugging in VS2010?
For example, in this code:
var addressGraphs = from a in context.Addresses
where a.CountryRegion == "Canada"
select new { a, a.Contact };
foreach(var ag in addressGraphs) {
Console.WriteLine("LastName: {0}, Addresses: {1}", ag.Contact.LastName.Trim(),
ag.Contact.Addresses.Count());
foreach(var Address in ag.Contact.Addresses) {
Console.WriteLine("...{0} {1}", Address.Street1, Address.City);
}
}
I'd like to set a breakpoint on the first 'foreach' line and then save the data in 'addressGraph' to a file.
where 'a' contains fields such as:
int addressID
string Street1
string City
<Ect.>
and 'Contact' contains fields such as:
string FirstName
string LastName
int contactID
<Ect.>
I'd like the file to contain the values of each of the fields for each item in the collection.
I don't see an obvious way to do this. Is it possible?
When your breakpoint is hit, open up the Immediate window and use Tools.LogCommandWindowOutput to dump the output to a file:
>Tools.LogCommandWindowOutput c:\temp\temp.log
?addressGraphs
>Tools.LogCommandWindowOutput /off
Note: You can use Log which is an alias for Tools.LogCommandWindowOutput
Update:
The > character is important. Also, the log alias is case sensitive.
See screenshot:
I also encoutered such a question, but in VS2013. I have to save a content of array while debugging.
For example, I need to save a content of double array named "trimmedInput". I do so:
Open QuickWatch Window from Debug menu (Ctrl+D, Q).
Put your variable in Expression and push Recalculate Button
You'll see all the values. Now you could select them all (Ctrl+A) and copy (Ctrl+C).
Paste (Ctrl+V) them in your favorite editor. Notepad, for example. And use them.
That's the simples way that I know. Without additional efforts. Hope that my description helps you!
P.S. Sorry for non English interface on screenshots. All necessary information are written in the text.
Something similar is possible with this method:
I built an extension method that I use in all of my projects that is a general and more powerful ToString() method that shows the content of any object.
I included the source code in this link:
https://rapidshare.com/files/1791655092/FormatExtensions.cs
UPDATE:
You just have to put FormatExtensions.cs in your project and change the Namespace of FormatExtensions to coincide to the base Namespace of your project. So when you are in your breakpoint you can type in your watch window:
myCustomCollection.ToStringExtended()
And copy the output wherever you want
On Visual studio Gallery search for: Object Exporter Extension.
be aware: as far as I worked with, it has a bug that block you from exporting object once in a while.
You can also call methods in the Immediate Window, and so I think your best bet would be to use an ObjectDumper object, like the one in the LINQ samples or this one, and then write something like this in the Immediate Window:
File.WriteAllText("myFileName.txt", ObjectDumper.Dump(addressGraph));
Depending on which ObjectDumper you decide to use, you may be able to customize it to suit your needs, and to be able to tell it how many levels deep you want it to dig into your object when it's dumping it.
Here's a solution that takes care of collections. It's a VS visualizer that will display the collection values in a grid while debugging as well as save to the clipboard and csv, xml and text files. I'm using it in VS2010 Ultimate. While I haven't tested it extensively, I have tried it on List and Dictionary.
http://tinyurl.com/87sf6l7
It handles the following collections:
•System.Collections classes
◦System.Collections.ArrayList
◦System.Collections.BitArray
◦System.Collections.HashTable
◦System.Collections.Queue
◦System.Collections.SortedList
◦System.Collections.Stack
◦All classes derived from System.Collections.CollectionBase
•System.Collections.Specialized classes
◦System.Collections.Specialized.HybridDictionary
◦System.Collections.Specialized.ListDictionary
◦System.Collections.Specialized.NameValueCollection
◦System.Collections.Specialized.OrderedDictionary
◦System.Collections.Specialized.StringCollection
◦System.Collections.Specialized.StringDictionary
◦All classes derived from System.Collections.Specialized.NameObjectCollectionBase
•System.Collections.Generic classes
◦System.Collections.Generic.Dictionary
◦System.Collections.Generic.List
◦System.Collections.Generic.LinkedList
◦System.Collections.Generic.Queue
◦System.Collections.Generic.SortedDictionary
◦System.Collections.Generic.SortedList
◦System.Collections.Generic.Stack
•IIS classes, as used by
◦System.Web.HttpRequest.Cookies
◦System.Web.HttpRequest.Files
◦System.Web.HttpRequest.Form
◦System.Web.HttpRequest.Headers
◦System.Web.HttpRequest.Params
◦System.Web.HttpRequest.QueryString
◦System.Web.HttpRequest.ServerVariables
◦System.Web.HttpResponse.Cookies
As well as a couple of VB6-compatible collections
In "Immediate Window" print following to get the binary dump:
byte[] myArray = { 02,01,81,00,05,F6,05,02,01,01,00,BA };
myArray
.Select(b => string.Format("{0:X2}", b))
.Aggregate((s1, s2) => s1 + s2)
This will print something like:
0201810005F60502010100BA
Change the '.Aggregate(...)' call to add blanks between bytes, or what ever you like.

Xcode 3.2 Debug: Seeing whats in an array?

Whilst debugging in Xcode_3.1.2 I am pretty sure I could see the contents of my NSString arrays. However after upgrading to 3.2 I only see the following ...
I know I can print the object in (gdb) using "po planetArray" or simply click in the debugger and "print description to console" I am just curious, as I am sure it worked prior to upgrading. Anyone know anything about this?
cheers gary
edit: data formatters is on and it shows what you see above ...
This is because GDB acts as if the variable you are viewing is out of scope while it really just is confused about what each part function or method call of the data formatter is returning (the data formatter is the "{(unichar *)Xcode_CFStringSummary($VAR, $ID)}:s" part you are seeing.
When you are debugging and you are in a method where you know a local variable must be in scope right now, open the debugger window and the area where you can see "Variable", "Value" and "Summary" column titles double click the "Summary" row entry for the variable you are interested in and enter the following (for array types like NSArray or NSCFArray):
"{(int)[$VAR count]} objects {(NSString *)[(NSArray *)$VAR description]}:s"
then press return. You have now overwritten the default data formatter provided by Xcode's GDB extension (to be found in various plists at "/Developer/Library/Xcode/CustomDataViews/") with your own data formatter string.
Your own overrides are saved at "~/Library/Application Support/Developer/Shared/Xcode/CustomDataViews/CustomDataViews.plist" and if you want to have the Apple default data formatter back just double click the row for a variable of the same type and delete whatever is there.
The nitty-gritty details: In the custom expression above the "{}" construct tells GDB to execute a command (as if you where executing it from GDB's debugger command line, which means the same restrictions apply: you need to specify the return type in cast parens in front of every function or method which returns something). The ":s" behind the closing curly brace tells Xcode and GDB to reference the "Summary" column. Also valid would be ":v" which references the "Value" column which most of the time is just the pointer value. Everything that is outside of the curly braces is shown verbatim.
Unfortuntely curly braces can't be nested which invalidates ternary operator conditionals.
So with the above data formatter you should see the following for an empty NSArray:
"0 objects (\n)"
If you want to write your own data formatters as GDB extensions (equivalent to specifying a function akin to Xcode_CFStringSummary above) you can do so. Take a look at the following header: "/Developer/Applications/Xcode.app/Contents/PlugIns/GDBMIDebugging.xcplugin/Contents/Headers/DataFormatterPlugin.h"
it will tell you all you need to know. But it can be hard to get it right. It might be easier and less error prone to just define another method on your class and call that from the data formatter string instead of "description".
In the Run > Variables View menu in Xcode, is "Use Data Formatters" enabled?
I am not sure if this helps but if you select the array value to wish to see in the debugger window and the go to the Menu : Run > Variables View > View Variable As
you can change it from "NSCFString *" to "NSString *". You then see the value so "Planet_1" for example.
Cheers,
Kevin

Resources