Problems with KMFAM Macro System

FWIW to answer your question about my code, the expression above just defines,

(when k is bound to the string "propertyList"),

an application of the pBoard.propertyListForType(...) method

@DeepHeat - Download and unzip this script, and stick it in the javascript action. Let me know if it works.

script 1.txt.zip (8.3 KB)

@ComplexPoint - I had to use more of your code to get it to work:

var result = ObjC.deepUnwrap(
	$.NSString.alloc.initWithDataEncoding(
		$.NSPasteboard.generalPasteboard.dataForType(type),
		$.NSUTF8StringEncoding));

Waiting to hear back if it works. Thanks, by the way. :grinning_face_with_smiling_eyes:

1 Like

Replaced contents of Javascript action with contents of new new zip file and triggered macro...

DEBUG LOG:
-------------

ENTER: Request: getNewActionFromClipboard
	ENTER: getNewActionFromClipboard
		getActionsClipboardType: com.stairways.keyboardmaestro.actionarray
		ENTER: getClipboardStringForType "com.stairways.keyboardmaestro.actionarray"
			Clipboard contains type
			Result from NSPasteboard.generalPasteboard.propertyListForType(com.stairways.keyboardmaestro.actionarray):
			EXIT: getClipboardStringForType "com.stairways.keyboardmaestro.actionarray"
		EXIT: getNewActionFromClipboard
	EXIT: Request: getNewActionFromClipboard

...and...

Screenshot 2021-07-03 at 21.32.59

I then took the liberty of disabling the "If the Log variable contains anything, display it (for debugging)" action and commenting out the following lines from the new script...

		if (currentLog)
			currentLog += "\n";
			var padding = _getIndentPadding(extraIndent);
			msg = msg.split("\n").map(s => `${padding}${s}`).join("\n");
			KMEngine.setVariable(_logVariableName, `${backticks}\n${currentLog}${msg}\n${backticks}`);

...and reran the macro, only to get this message

Screenshot 2021-07-03 at 21.38.47

I checked and double-checked that I had deployed the correct script, but still got the same message when repeating your instruction.

:cry:

Try this. It probably won't solve the problem, but it'll fix that logging error you got. I need to make sure the logging error wasn't contributing to the problem.

Oh, and don't forget to actually select an action - I know this is obvious, but I just ran it without selecting an action, and I was stumped for a minute, so it's always good to make sure. :grinning_face_with_smiling_eyes:

script 2.txt.zip (8.3 KB)

I added "v2 -" to the first line in the log, so you can be sure you used the new script. :grinning_face_with_smiling_eyes:

Downloaded and replaced script..

DEBUG LOG:
-------------

ENTER: v2 - Request: getNewActionFromClipboard
	ENTER: getNewActionFromClipboard
		getActionsClipboardType: com.stairways.keyboardmaestro.actionarray
		ENTER: getClipboardStringForType "com.stairways.keyboardmaestro.actionarray"
			Clipboard contains type
			Result from NSPasteboard.generalPasteboard.propertyListForType(com.stairways.keyboardmaestro.actionarray):
				
			EXIT: getClipboardStringForType "com.stairways.keyboardmaestro.actionarray"
		plistString:
			
		EXIT: getNewActionFromClipboard
	EXIT: v2 - Request: getNewActionFromClipboard

...and our old friend...

Screenshot 2021-07-03 at 22.27.10

Do me a favor and right after you get the error, run that other macro that shows the clipboard contents, and post the results. I just want to double-check my assumptions.

No problem.... here you go..

{
  "public.utf8-plain-text as string": "If the Log variable contains anything, display it (for debugging)\n",
  "public.utf8-plain-text as data": "If the Log variable contains anything, display it (for debugging)\n",
  "com.stairways.keyboardmaestro.actionarray as propertyList": [
    {
      "ActionColor": "Yellow",
      "TimeOutAbortsMacro": true,
      "ElseActions": [],
      "MacroActionType": "IfThenElse",
      "Conditions": {
        "ConditionListMatch": "All",
        "ConditionList": [
          {
            "ConditionType": "Variable",
            "VariableValue": "value",
            "Variable": "kmfamLog",
            "VariableConditionType": "IsNotEmpty"
          }
        ]
      },
      "ElseActionListDisclosed": false,
      "ThenActions": [
        {
          "Action": "DisplayWindow",
          "StyledText": {},
          "MacroActionType": "InsertText",
          "Text": "DEBUG LOG:\n-------------\n\n%Variable%kmfamLog%"
        },
        {
          "TimeOutAbortsMacro": true,
          "MacroActionType": "Pause",
          "Time": ".3"
        },
        {
          "Application": {
            "BundleIdentifier": "com.stairways.keyboardmaestro.editor",
            "Name": "Keyboard Maestro",
            "NewFile": "/Applications/Keyboard Maestro.app"
          },
          "TimeOutAbortsMacro": true,
          "AlreadyActivatedActionType": "Normal",
          "ReopenWindows": false,
          "MacroActionType": "ActivateApplication",
          "AllWindows": true
        }
      ],
      "ActionName": "If the Log variable contains anything, display it (for debugging)"
    }
  ]
}

OK, one more time, with feeling:

script 3.txt.zip (8.3 KB)

Here we go..... code swapped out and action triggered..

DEBUG LOG:
-------------

ENTER: v3 - Request: getNewActionFromClipboard
	ENTER: getNewActionFromClipboard
		getActionsClipboardType: com.stairways.keyboardmaestro.actionarray
		ENTER: getClipboardPlistForType "com.stairways.keyboardmaestro.actionarray"
			Clipboard contains type
			Result from NSPasteboard.generalPasteboard.propertyListForType(com.stairways.keyboardmaestro.actionarray):
				[
				  {
				    "ActionColor": "Yellow",
				    "TimeOutAbortsMacro": true,
				    "ElseActions": [],
				    "MacroActionType": "IfThenElse",
				    "Conditions": {
				      "ConditionListMatch": "All",
				      "ConditionList": [
				        {
				          "ConditionType": "Variable",
				          "VariableValue": "value",
				          "Variable": "kmfamLog",
				          "VariableConditionType": "IsNotEmpty"
				        }
				      ]
				    },
				    "ElseActionListDisclosed": false,
				    "ThenActions": [
				      {
				        "Action": "DisplayWindow",
				        "StyledText": {},
				        "MacroActionType": "InsertText",
				        "Text": "DEBUG LOG:\n-------------\n\n%Variable%kmfamLog%"
				      },
				      {
				        "TimeOutAbortsMacro": true,
				        "MacroActionType": "Pause",
				        "Time": ".3"
				      },
				      {
				        "Application": {
				          "BundleIdentifier": "com.stairways.keyboardmaestro.editor",
				          "Name": "Keyboard Maestro",
				          "NewFile": "/Applications/Keyboard Maestro.app"
				        },
				        "TimeOutAbortsMacro": true,
				        "AlreadyActivatedActionType": "Normal",
				        "ReopenWindows": false,
				        "MacroActionType": "ActivateApplication",
				        "AllWindows": true
				      }
				    ],
				    "ActionName": "If the Log variable contains anything, display it (for debugging)"
				  }
				]
			EXIT: getClipboardPlistForType "com.stairways.keyboardmaestro.actionarray"
		EXIT: getNewActionFromClipboard
	EXIT: v3 - Request: getNewActionFromClipboard

...and....

...one of these....

Screenshot 2021-07-03 at 22.27.10

Upon entering the necessary details, we get this....

DEBUG LOG:
-------------

ENTER: v3 - Request: saveNewAction
	EXIT: v3 - Request: saveNewAction

F15... gives the following..

DEBUG LOG:
-------------

ENTER: v3 - Request: getSelectData
	EXIT: v3 - Request: getSelectData

.....and....

Superb! Excellent! Wonderful! :partying_face: :partying_face: :thinking: :face_with_hand_over_mouth: :disappointed_relieved: :cry: :sob:
.
.
.

Hmmm. Create new action and F15

DEBUG LOG:
-------------

ENTER: v3 - Request: getSelectData
	EXIT: v3 - Request: getSelectData

It's still there... click "OK" to insert the action into the new macro...

DEBUG LOG:
-------------

ENTER: v3 - Request: applyAction
	getActionsClipboardType: com.stairways.keyboardmaestro.actionarray
	EXIT: v3 - Request: applyAction

It's not there...

Rinse and Repeat...

Still not there. No error messages.

Just to ensure that I haven't forgotten the process, I return to the KMFAM YouTube video once again and confirm that I'm doing exactly as the nice chap on the video states. No deviation. Watch it a few more times, just in case.

:disappointed_relieved: :cry: :sob:

Nevertheless, I disable and comment-out the debug actions and statements (as before) and try again, but to no avail. The action is stored but not inserted.

The file "FavoriteActions.json" contains this:

{"id":"FavoriteActionsData","version":"1.0","actions":[{"uuid":"41D6B087-9FEC-4502-8692-E01BC6F45762","name":"Tutorial Video","script":"9B5DEA2E-919F-4B28-A320-8DDD328C3E2C","type":"macro","imageFileName":"41D6B087-9FEC-4502-8692-E01BC6F45762 1472826817221.jpg"},{"uuid":"0D22EFB4-47AC-4E5E-A997-83268EF5C500","name":"If the Log variable contains anything, display it (for debugging)","keywords":"","script":"[{\"ActionColor\":\"Yellow\",\"TimeOutAbortsMacro\":true,\"ElseActions\":[],\"MacroActionType\":\"IfThenElse\",\"Conditions\":{\"ConditionListMatch\":\"All\",\"ConditionList\":[{\"ConditionType\":\"Variable\",\"VariableValue\":\"value\",\"Variable\":\"kmfamLog\",\"VariableConditionType\":\"IsNotEmpty\"}]},\"ElseActionListDisclosed\":false,\"ThenActions\":[{\"Action\":\"DisplayWindow\",\"StyledText\":{},\"MacroActionType\":\"InsertText\",\"Text\":\"DEBUG LOG:\\n-------------\\n\\n%Variable%kmfamLog%\"},{\"TimeOutAbortsMacro\":true,\"MacroActionType\":\"Pause\",\"Time\":\".3\"},{\"Application\":{\"BundleIdentifier\":\"com.stairways.keyboardmaestro.editor\",\"Name\":\"Keyboard Maestro\",\"NewFile\":\"/Applications/Keyboard Maestro.app\"},\"TimeOutAbortsMacro\":true,\"AlreadyActivatedActionType\":\"Normal\",\"ReopenWindows\":false,\"MacroActionType\":\"ActivateApplication\",\"AllWindows\":true}],\"ActionName\":\"If the Log variable contains anything, display it (for debugging)\"}]","type":"action","imageFileName":"0D22EFB4-47AC-4E5E-A997-83268EF5C500 1625353884623.jpg"}]}

And the clipboard macro has this.....

{
  "public.utf16-plain-text as propertyList": "TLDTLW_",
  "public.utf16-plain-text as string": "U\u0000T\u0000L\u0000D\u0000T\u0000L\u0000W\u0000_\u0000",
  "public.utf16-plain-text as data": "U\u0000T\u0000L\u0000D\u0000T\u0000L\u0000W\u0000_\u0000",
  "public.utf8-plain-text as propertyList": "UTLDTLW_",
  "public.utf8-plain-text as string": "UTLDTLW_",
  "public.utf8-plain-text as data": "UTLDTLW_",
  "com.apple.traditional-mac-plain-text as propertyList": "UTLDTLW_",
  "com.apple.traditional-mac-plain-text as string": "UTLDTLW_",
  "com.apple.traditional-mac-plain-text as data": "UTLDTLW_",
  "org.nspasteboard.source as propertyList": "com.stairways.keyboardmaestro.engine",
  "org.nspasteboard.source as string": "com.stairways.keyboardmaestro.engine",
  "org.nspasteboard.source as data": "com.stairways.keyboardmaestro.engine"
}

:persevere:

OK, there's another direction I can go. KM added a "Copy as XML" option after I wrote this code, which I can use instead of just the standard "Copy". And it actually gives me exactly what I want.

I'll have to dig back into my code to remember how it works, so it might take me a little while to rework the code. But hang in there, help is on the way,

1 Like

I'm not. If I was, I would probably have Sherlocked it by now. :slight_smile:

Please, by all means! I couldn't imagine working in KM without it, and I know a lot of people agree. I would help you in any way I can, and you can have my code and use it anyway you want, although I suspect you'd end up writing your own code. I'd even create something to import people's existing actions.

I know the likelihood is small, but the offer is there. I don't care about attribution or residuals or anything like that - that's not my style - I only care that it would be a feature that's much more "visible" than some macro people might stumble across.

I'm pretty sure how you'll respond to this, but the offer is there, regardless. :slightly_smiling_face:

2 Likes

Thanks Dan, yes, I know all the that - the point I was making is, I don't use it, because for me it isn't something I'm after. And while I should still do something to resolve the issue for those of you who do want that facility, the fact that I don't inevitably means it is further down on the todo list. I am only human after all!

Believe me, I totally understand, and no worries.

1 Like

@DeepHeat - I think you're going to like this.

Step 1: Modify "[kmfam]~Add (Sub-Macro)"

image

  1. Disable the "Copy" action.
  2. Add an action that selects "Edit>Copy as>Copy as XML" from the Keyboard Maestro menu.

Step 2: New script (it doesn't log anything now, by the way):

script 4.txt.zip (8.1 KB)


After I slept on it a little, I realized the changes were pretty simple.

Good luck!

2 Likes

Oh Dan!

I love you and want to have your babies (if were physically possible)

It's a bundle of joy. It works perfectly! Normality has returned to my little corner of the world.

Oh! The happiness! The joy!

You are beautiful people.

:beers:

Many Thanks for your time, your effort, the new code, the sun in the sky, the flowers in the garden, the air that I breath. Thank You for everything. Send me your invoice.

Time to dust off my old "Best of Barry White" vinyl album and chill a celebratory bottle of fizz!

1 Like

@DanThomas
What steps do I need to do to replace KMFAM with this version?

I remember having issues but didn't want to try your patience, also in Big Sur.
Thanks

:laughing: I had to type, erase, and re-type my reply multiple times, because my mind went right to the gutter. So I'll resist the urge, and post something more appropriate for this venue. :wink:

so... Awesome! Glad we worked it out. Now I just have to figure out how to package this for redistribution. I really don't want to re-do the installer, if I can help it.

I've got an idea, so if you're willing to be the guinea pig, I'll whip something up.