Is there a way to read the values from an app pasteboard?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>creator</key>
<string>MoneyMoney 2.3.3</string>
<key>transactions</key>
<array>
<dict>
<key>currency</key>
<string>EUR</string>
<key>name</key>
<string>Telekom Deutschland GmbH Landgrabenweg 151</string>
<key>purpose</key>
<string>Mobilfunk Kundenkonto</string>
<key>valueDate</key>
<date>2017-11-27T12:00:00Z</date>
</dict>
</array>
</dict>
</plist>
In my case I need the key:name an his string value.
There are various ways to read the top level array or dictionary from a plist-format string.
I tend to use, through JavaScript for Automation, either:
(Some plists are dictionaries at their top level, and some array arrays, if the first method returns nothing, then we can try the second).
Your example is a dict at the the top level, so the simplest example of reading it might look something like the sample macro and JXA snippet below. (Both methods require that the plist is first written out to disk as a temporary text file).
Example - Read value from plist.kmmacros (20.1 KB)
To slightly generalize the key that you are reading, you could also write things like:
(() => {
const
kme = Application('Keyboard Maestro Engine'),
[strPlistPath, strKey] = ['plistPath', 'plistKey']
.map(k => kme.getvariable(k));
return ObjC.deepUnwrap(
$.NSDictionary.dictionaryWithContentsOfFile(
$(strPlistPath)
.stringByStandardizingPath
)
).transactions[0][strKey]
})();
Thanks. My main problem is: How can I write the app.pasteboard to a file … or a variable?
Got it. What’s the utility which is displaying the app clipboard strings in your screen-shot ?
https://langui.net/clipboard-viewer/
I use this tool for some clipboard inspections.
OK - MoneyMoney and clipboard viewer both seem out of reach from UK appstore, but approaching from another direction, if you copy something from MoneyMoney, and run this with the JS tab selected in Script Editor, does the list include the clip type that you are looking for ?
(function() {
ObjC.import('AppKit');
return ObjC.deepUnwrap(
$.NSPasteboard.generalPasteboard.pasteboardItems.js[0].types
);
})();
And if you copy again from MoneyMoney and run this ?
(function() {
ObjC.import('AppKit');
const strClipType = 'com.moneymoney-app.pasteboard';
return ObjC.deepUnwrap(
$.NSPasteboard.generalPasteboard.propertyListForType(strClipType)
);
})();
1 Like
It works! 1000 THANKS TO YOU!
1 Like
Good !
If you prefer Applescript you could try something like
use framework "Foundation"
use scripting additions
-- unwrap :: NSObject -> a
on unwrap(objCValue)
if objCValue is missing value then
return missing value
else
set ca to current application
item 1 of ((ca's NSArray's arrayWithObject:objCValue) as list)
end if
end unwrap
set strClipType to "com.moneymoney-app.pasteboard"
set ca to current application
set maybeRec to unwrap(((ca's NSPasteboard's generalPasteboard())'s ¬
propertyListForType:strClipType))
2 Likes