First off, thanks for this!! Itās truly awesome and has opened up a new level of usefulness for OG for me.
However, Iād like to request a missing API for manipulating the user data (metadata) associated with graphic elements. According to the discussion here (https://omni-automation.com/omnigraffle/metadata-00.html), itās possible to get or set specific items by key, but how do I get the list of keys defined for the given element?
This is pretty crucial for my use case. Also, it would be very handy (so I donāt have to write it in JS) to allow you to get graphics by only the user data key and not a specific value, e.g.
var g = canvas[0].allGraphicsWithUserDataKey("...");
Iām not sure if thereās a better place to ask this question or get specific support on the automation, but if so, please let me know.
The userData property of a graphic (or the background) returns a vanilla JavaScript object, on which all the built-in JS Object methods can be used, so no special API is needed.
All you need is the standard JS Object.keys(objReference) which will return an array of the user data keys, over which you can map to get values.
(The discovered keys can also, of course, be used in the normal JS way to get the keyed values of the userData object).
Thatās what I was trying to do. Unfortunately, in my version, this is what happens:
g = document.windows[0].selection.graphics[0] [object Shape] userData = g.userData undefined
Thatās why I was a little confused. I tried a bunch of iterations on what the property might be (figuring it was just a plain object), but I didnāt get the results you did.
Ah you are using 7.3, in which case a JXA approach is possible, but omniJS and the omni-automation site are not yet relevant. (My understanding is that omniJS is a 7.4 test build innovation)
Are you in fact using JavaScript for Automation, e.g. from Script Editor ?
(userData is also accessible (using a slightly different idiom) in that case, but we first need to check which JS interface to OG you are using :-)
I just followed the original instructions for 7.3 per the title of the thread.
Iām playing with my first plugin trying to basically interrogate a fairly complex diagram I have. All the important shapes have been augmented with user data so I know what they semantically represent, and then Iām trying to do things based on that understanding (that data property editor in the inspector for 7.3 is buggy as hell, BTW).
I only started this today, so first I was following the examples on the omni-automation site via the console, and then I started replacing functionality in the sample skeleton plugin.
Iām running this on OS X (El Capitan) if that makes a difference.
However, thatās for more general use down the road. For now, Iām looking for some specific properties, and thatās sufficient. Iāve also just iterated over the graphics objects to offset the busted canvas method to get the objects via user data values, so Iām not dead in the water. Just trying to figure out what is and is not possible.
What kinds of other, more sophisticated stuff can you do like access the filesystem and send/receive web requests? For now, what Iām doing is kinda a neat toy, but if I canāt actually integrate this script with something else, the usefulness I was hoping for wonāt be there.
Maybe thereās a sandbox permission model or something where you could prompt the user for accessing certain modules/functions? Make the plugin registry work like authorization for OAuth style apps?
Iām not quite sure what you mean by JXA, as Iām doing it from within OG. Within the OG console, this is what I get taking the userData-as-method approach:
g [object Shape] g.userData() // // TypeError: g.userData is not a function. (In 'g.userData()', 'g.userData' is undefined) undefined:1
JXA (JavaScript for Automation) is a marketing name for JavaScript use of the ApplesScript scripting dictionaries. (So the snippet above works only in Script Editor, with the language tab at top left set to āJavascriptā)
I just tried on 7.3 (thanks, I had forgotten that 7.3 included an early build of omniJS) and I was able to reproduce your result ā graphic.userData is still undefined in 7.3, but works in 7.4, if you are happy to use test builds.
Have now downloaded a 7.4 build and made more progress, in addition to uncovering the docs for the URL method. Looks like I can pull things in, but I canāt push things out.
The URL#fetch signature only appears to support functions as arguments and nothing along the lines of working draft #fetch or proxying the properties of NSMutableURLRequest like providing #method or #body.
My objective is to trigger push notifications so that I can use OG documents as the definitive source of information vs. being a passive reflection of information. If I have a way to make POST requests, then everythingās fantastic.
Iāve now successfully poked OG from node via a wrapper around the āosascriptā utility, so things are getting more interesting. However, Iād still really, really prefer to be able to push things while the document is open rather than doing things via remote-control from another source.
Any way this can be included in 7.4? Iām now using this build:
Also, Iām still seeing #allGraphicsWithUserDataForKey return zero-length arrays for values I know are in the canvas. Should this work? It it a known issue?
Another thing I was wondering about the architecture of the implementation was why something like CommonJS wasnāt used for defining modules since itād make things easier to re-use vs. the approach taken?
It is what it is, I guess, but was curious why OmniJS went its own way on this.
Worth flagging through OmniGraffle Menu > Help > Contact Omni ā I donāt think itās always possible for them to get around to reading these threads, which are mainly positioned as user to user.
(The ideal thing may be to post here, and then forward a link to omni support through that app menu item)
Yeah, thatās what I did as a workaround as well.
I saw the @SupportHumans reference above, so Iāll try that first, and then see what happens. It isnāt critical since thereās a workaround, but Iād like to see some of the other things addressed that I mentioned a couple of posts ago.
I also noticed that this build is ignoring the toolbarLabel strings key and just using the menu label in the toolbar text. Thatās kinda annoying since itās generally too long for a toolbar and the docs say it works. Must work on iOS since I guess there you donāt have to manually add the icons.
Thanks for the feedback and confirmation of the issue.
OT: are you from/in ZA, or just like African animals? Kudu is an odd choice of animal otherwise ;)
Another one for the @SupportHumans that Iām not sure qualifies for a Contact Omni⦠yet:
Any idea how to dynamically change the labels, tooltips and icons so as to implement a ātoggleā action?
What I want is to be able to alter graphics in the canvas, save their original state and restore them outside of the context of the undo/redo mechanism. This is perfectly valid for my use case, even though it might not seem like it.
I see we have access to the this.plugIn reference, but I donāt see any properties, and nothing semi-obvious seemed to give me any values, e.g. label, menuLabel, ā¦
I havenāt really experimented there yet, but in one context I have thought of simply cycling the referenced icon from the JXA interface, which speaks to the file system.