Cannot access cocoa property via applescript - cocoa

I have two string properties setup in my cocoa application's app delegate which are KVC compliant. My .sdef exposes them to applescript as text read-write properties.
When I use applescript to do the following, my properties are returned correctly:
tell application "iKeepFit"
activate
properties
end tell
What gets weird is that when I try to access the property by its name, applescript editor will popup a dialog saying my app had an error. Yet xcode debug output shows no messages. Previously when my .sdef was wrong then xcode would show errors if I ran the script calling my app when it is attached to the debugger.
E.g.
propertyname <- error "Can’t get propertyname." number -1728 from «class dact»
set propertyname "value" <- error "Can’t set propertyname." number -10006 from «class dact»
Is there something that would typically cause this behavior?
I've gone through two cocoa books, an applescript book and lots of sample code and apple documentation, but they seem to all implement applescript support differently. What I've got so far is the closest to working code from trying them all out. Here's my .sdef file:
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<!-- use XInclude to include the standard suite
<xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/>
-->
<suite name="iKeepFit Scripting" code="iKft"
description="Commands and classes for iKeepFit Scripting">
<class name="application" code="capp" description="The application class.">
<!-- the following names the Objective-C class where Cocoa will look for
the property accessor methods for the properties we define for
this AppleScript class. -->
<cocoa class="MyApplication"/>
<!-- the 'done' property. -->
<property name="completedactivity" code="dAct" description="An activity that was completed" type="text" access="rw">
<cocoa key="doneActivity"/>
</property>
<!-- the 'cancel' property. -->
<property name="canceledactivity" code="cAct" description="An activity that was canceled" type="text" access="rw">
<cocoa key="cancelActivity"/>
</property>
<responds-to name="completed">
<cocoa method="handleCompletedActivityScriptCommand:"/>
</responds-to>
</class>
</suite>
I commented out the standard suite stuff because surprisingly it's broken and produces the following error: .sdef warning for argument 'FileType' of command 'save' in suite 'Standard Suite': 'saveable file format' is not a valid type name.
Please help. Thanks.

I was able to find a solution. In Snow Leopard, Applescript apparently doesn't know what properties are defined in the application unless it's surrounded by a using terms from block.
using terms from application "iKeepFit"
set doneActivity to "test"
end using terms from
And for some reason the <class> element needed an id="blah" attribute in it - the only reason I've found that is by looking at the output of an .sdef editing program. The real frustrating part is that this isn't in any of the examples or documents I've read.

Related

Extending Visual Studio 2017 XML editor

I'm trying to improve our workflow with some XML-configuration files we use in a Visual Studio Solution. I figured I'll start with explaining what I'm trying to accomplish and then explain some of my ideas that I've tried for several hours without success.
The Problem
I'm working with a system where the data model is configured in a database, the models are also stored on disk using xml-files, these are then synced during startup of the app. Here's part of the stuff that are synced:
Data Types
All data types lives in one XML configuration file per data type and each has some properties like Name and Key. All data types are configured in the same folder, example: /config/dataTypes
Example
textString.config
<?xml version="1.0" encoding="UTF-8" ?>
<DataType Key="a45c9a94-09d7-4df9-85e6-d6930abc6c12" Name="Textstring">
textArea.config
<?xml version="1.0" encoding="UTF-8" ?>
<DataType Key="b104788f-4e2f-4592-9387-8b3861bd8046" Name="Textarea">
Entity Types
Think of these as models with X number of properties, each property is configured and connected to a Data Type.
Example
customer.config
<?xml version="1.0" encoding="UTF-8" ?>
<Entity>
<Properties>
<Property Name="Firstname" TypeKey="a45c9a94-09d7-4df9-85e6-d6930abc6c12" />
<Property Name="Lastname" TypeKey="a45c9a94-09d7-4df9-85e6-d6930abc6c12" />
<Property Name="Description" TypeKey="b104788f-4e2f-4592-9387-8b3861bd8046" />
</Properties>
</Entity>
My end goal is to provide intellisense when editing a Entity Type so that I'll get all the Data Types as suggestions when entering the "TypeKey" property of the Property element. Preferably showing the Name of the data type in the dropdown list and when choosing it adding the guid as value for the TypeKey-property. I would also like to show the Data Types name when hovering the GUID with the mouse (or in some other way).
As you can imagen during the process with a project new data types can be added so the intellisense needs to be dynamic based on the files in the data types-folder.
I should also mention that these configuration files also can be edited from a UI in the application and I don't have control over how they are serialized, hence - there is no XML namespace in the files, they look like in the examples above.
We also have multiple different VS-solutions with different setups of Data Types and Entity Types. So we need individual intellisense in each project.
What I've tried
My first idea was to create a VS-extension that creates a dynamic XML Schema XSD-file based on the files in the data types folder. The VS would then pick up and use the XSD for XML-files in the Project, turns out that this only works with a namespace configured (remember, I can't add namespaces since I don't control the external app).
To get around this it worked to manually add the schema-file to the XML file while editing the file. (Like this: https://learn.microsoft.com/en-us/visualstudio/xml-tools/how-to-select-the-xml-schemas-to-use?view=vs-2019). The problem with this is that it needs to be done for each xml-file and the setting is not stored.
I then started to play with the VS extension possibilities to try to automatically configure this Schema to a XML-file that is opened. Turns out I had a really hard time to get the "configuration object" that is pushed to the Properties Browser when the XML file is opened. I managed to get a event-handler setup that was triggered when the XML files as getting "focus" but I was stucked trying getting the properties from the Properties Browser.
I also tried another approach with a custom "code completion"-extension but it made the UI feel very "cluttered" while editing.
After spending about 10 hours playing around with this I feel I don't really have a good path to a solution as my experience with VS-extensions is not that extensive.
I would love to get some feedback and ideas on how to approach this problem, since the XSD is different from each project if I go down the "dynamic" path we can't use the global VS settings since each project has different data types hence needs different allowed values for the TypeKey property.
One approach that I'm thinking about is to use a generic XSD (allowing all values for the TypeKey) in the Global Schema Cache for Visual Studio and create a "code completion"-feature for just the TypeKeys.
Any thoughts and pointers in the right direction would be very much appreciated.

Difference between Ti.App.VariableName & Ti.App.Properties

In Titanium, what is the differences between the following two lines of codes?
Ti.App.currentUser = "user1";
Ti.App.Properties.setString("currentUser", "user1");
Ti.App.Properties :
The App Properties module is used for storing application-related data in property/value pairs that persist beyond application sessions and device power cycles.
App Properties in the tiapp.xml file
App properties defined in the tiapp.xml file may be accessed using these APIs. An app property is defined inside the root-level <ti:app> element with the <property> element. Use the name attribute to define your property name and place the value inline with the <property> element. For example, to define an app property called foo with the value 42:
<?xml version="1.0" encoding="UTF-8"?>
<ti:app xmlns:ti="http://ti.appcelerator.org">
<property name="foo" type="string">42</property>
</ti:app>
Ref : http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App.Properties
Ti.App.VariableName stores a variable not persistent and only for the App runtime.
The top-level App module is mainly used for accessing information about the application at runtime, and for sending or listening for system events.
The App module exposes a number of properties set in the tiapp.xml file.
Three of these properties, the application name, ID, and URL, must be specified when the application is created.
While most values may be changed by editing the tiapp.xml file after creating the project, the GUID is automatically generated and should not be changed.
More details Titanium.App
At the end if you want store and retrieve values in tiapp.xml file you should use Titanium.App.Properties
Abada does a great job explaining the difference, but let me emphasis that you should not add any custom properties to Titanium proxy objects like Ti.App. This is bad practice because it may lead to memory leaks and unpredictable behaviour. These objects are not 100% JS but bridge to Obj-C/JAVA/C+

RSpec test uploaded xml file that fills out dynamic form

I am writing an automation test suite using RSpec, capybara, selenium web driver, and poltergeist. I do not have access to the codebase of the web app itself, only the test suite.
What happens is the client uploads an xml file, pieces of that xml file populate a form. The form is also dynamic, so fields can be added dependent on the contents of the xml file.
My mission is to write a test that ensures that the values of the xml file match what is being populated within the form.
Any help would be greatly appreciated. Below is a sample of one of the xml files I am attempting to test.
<?xml version="1.0" encoding="UTF-8"?>
<LOAN_APPLICATION>
<_DATA_INFORMATION>
<DATA_VERSION _Name="Date" _Number="20140926"/>
<DATA_VERSION _Name="1003" _Number="3.20"/>
</_DATA_INFORMATION>
<ADDITIONAL_CASE_DATA>
<TRANSMITTAL_DATA BelowMarketSubordinateFinancingIndicator="N" BuydownRatePercent="0.000" />
</ADDITIONAL_CASE_DATA>
<ASSET _CashOrMarketValueAmount="10000.00" />
<ASSET _AccountIdentifier="123456"/>
<ASSET _AccountIdentifier="1234567" _CashOrMarketValueAmount="100000.00" />
<ASSET _AccountIdentifier="6465456" _CashOrMarketValueAmount="50000.00" />
<InterviewersEmployerPostalCode="200121234" InterviewersTelephoneNumber="2023333333" ApplicationTakenMethodType="FaceToFace" InterviewerApplicationSignedDate="20111011" InterviewersEmployerName="ABC Mortgage" InterviewersName="John Done"/>
<CONTACT_POINT _Type="Email" _Value="Jimmy.Johns#abc.com"/>
</BORROWER>
</LOAN_APPLICATION>
John, you could create a fixture that reproduces an XML file like the one you pasted. Then you run your services, methods etc against it, and expect (or not) to parse back the contents of the fixture. You could also test another fixtures with invalid fields to ensure your app has contingencies to break down gracefully if there are any invalid fields.

WIX: persist session data between C# CustomActions and subsequently displayed WIX Dialog

I am new to WIX and have been tasked with creating an installer that does
the following:
*Deploys a build of our application without overwriting the App.Config file
for the application
*Loads the key/values in the App.Config file and prompts the user with the
"defaults" (existing values) and allows them to modify them before finishing
*SAVES the values the user provided (or defaults if the user made no
changes) back to the App.Config file for use with the application.
I've got the WIX dilalogs and custom actions laid out successfully where
after InstallFinalize, my "LoadDefaultOptions" CustomAction is executed,
which successfully takes the installation directory and the app config file
name, loads it in an XML reader, and parses the key/value pairs, setting
them into the session variable in this manner:
session[key.toUpper()] = value;
My custom action(s) are defined as:
<CustomAction Id="LoadDefaultOptions" Return="asyncWait" Execute="immediate" BinaryKey="aeserverDbDialogPackage.dll" DllEntry="LoadDefaultOptions"/>
<CustomAction Id="SetConfigOptions" Return="check" Execute="immediate" BinaryKey="aeserverDbDialogPackage.dll" DllEntry="SetConfigOptions"/>
The LoadDefaultOptions executes as such:
<Custom Action="LoadDefaultOptions" After="InstallFinalize" />
I have the custom dialog edit properties set like this:
<Control Id="CCPDbConnString" Type="Edit" X="20" Y="62" Width="150" Height="18" Property="CCPCONNECTIONSTRING" Indirect="no" />
There's a matching Property tag earlier in the WXS file like this:
<Property Id="CCPCONNECTIONSTRING" Secure="yes" ></Property>
...And the LoadDefaultOptions customAction overwrites the session var like
this:
session["CCPCONNECTIONSTRING"] = <value parsed from file>;
According to session logs, this works as expected, the xml parse works, and
the session vars are set.
My problem is when my custom dialog comes around to prompt the user with
those stored defaults AFTER the LoadDefaultOptions CustomAction has run.
The ORIGINAL property values of the session variables seem to have "stuck"
instead of being overwritten by the custom action that loaded the defaults
via the xml file and stored them in the session. (they are blank as their
original properties are defined, or in the case I define them otherwise,
they show those values instead of the session written values)
How do you get Dialogs to "read" overridden session variables by
CustomActions?
Ultimately I want to load those values from the app config, prompt them back
to the user in an optional dialog prompt off the exit screen (which works so
far, aside from not getting updated session vars), and then on command from
that prompt dialog, run another custom action to re-write the App.Config
file with the settings provided from the custom dialog...
I just can't get the session vars to PERSIST!!!
Any ideas? am I completely off base attempting to use the session in this manner? how else could I parse the app.config file, and allow an installation user to change app settings if not by session?
Apparently, part of what I'm trying to do is more or less impossible... You cannot modify the session vars in the InstallExecuteSequence for use in dialogs... this can only be done in the InstallUISequence...
Therefore, I cannot READ AND PROMPT USERS FROM my App.Config on first installs as the file will never have been deployed during the period of time that it would be possible to do.... Seems the only time this would work is during an UPGRADE where the App.Config file exists from a prior install in the same location from which the original install occurred.
I'm going to go at it from this point of view, with NO (or hard-coded) default settings during a fresh installation, with an attempt to parse and use as defaults EXISTING app.config settings during upgrade installations... That should take care of my requirements!
If you schedule your custom action after InstallFinalize it won't run elevated during a managed installation / UAC type story. I also have a question, have you considered moving this configuration data to the application where it's easier to manage it as a first-run pattern?

Debugging in J2ME Polish

How to debug the J2ME Polish MIDlet?
How can I show the logs which are generated?
You can easly log statements with J2ME Polish using the following:
//#debug
System.out.println("Error...");
Using //#debug with J2ME Polish indicates a pre-processing directive to log the println statement.
There are various levels of logging, including debug, info, warn, error and fatal. You can define your own logging levels but I find that over exhaustive for most situtations.
The best thing I found was to add a handler to the build file within the debug section.
<handler name="http">
<parameter name="server" value="http://a.server.com:80/Debug/" />
</handler>
Will post any log information straight to a server, so you can literally see the log flow in as your application is running.
Or you can add a handler that logs to an RMS and use the J2ME Polish Logviewer sample application to view the logs stored within the RMS. The can be found in the sample directory of your J2ME Polish installation.
<handler name="rms">
<parameter name="useBackgroundThread" value="false" />
</handler>
Remember to set the varriables in the logview build file. See below:
<variables>
<variable name="polish.log.MIDletSuite" value="Demonstrator" />
<variable name="polish.log.Vendor" value="Enough Software" />
</variables>
I had a collegue at work try to debug via bluetooth but I think this doesn't actually work.
Just a note to any one reading this who is new J2ME, you cannot debug on device! MIDlets and J2ME were first concieved in the late 90's.

Resources