Help. Creating first plugin

I'm new to the plugins and I just want to create a very basic plugin to create a new document from any content. I will use the clipboard for demo purposes.

I know this can be done as a macro, but I want to have it as a plugin, since I want to write some other later.

this is my Keyboard Maestro Action.plist

<?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>Author</key>
	<string>Eduardo</string>
	<key>Icon</key>
	<string>icon.png</string>
	<key>Name</key>
	<string>BBEdit - new file</string>
	<key>Script</key>
	<string>main.scpt</string>


	<key>Parameters</key>
	<array>
		<dict>
			<key>Label</key>
			<string>content</string>
			<key>Type</key>
			<string>TokenText</string>
		</dict>
	</array>
</dict>
</plist>

this is my main.scpt content

#!/usr/bin/osascript -l JavaScript

'use strict';
(function run(argv) {

    // arguments
    const command = argv[0];
    const tabName = argv[1];

    // get app
    const BBEdit = Application('BBEdit');
    BBEdit.includeStandardAdditions = true;

    // content
    //--- GET A REFERENCE TO THE KM ENGINE ---
    var kme = Application("Keyboard Maestro Engine");
    var content = kme.getvariable('KMPARAM_content');
    // let content = BBEdit.theClipboard();


    // activate
    BBEdit.activate();

    // new document
    BBEdit.make({
        "new": "document",
        "withProperties": {
            "text": content
        }
    });

})();

whenever I run it I get the following

Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions/BBEdit - new file/main.scpt:5:6: script error: Expected end of line, etc. but found “/”. (-2741)

or Library/Application Support/Keyboard Maestro/Keyboard Maestro Actions/BBEdit - new file/main.scpt:1:2: script error: Expected end of line, etc. but found unknown token. (-2741)

any ideas what could be happening?

.scpt is the extension for AppleScript, so it is being executed as an AppleScript, which it is not.

Try using .sh since it is basically a bash script (bash is then running the comment in the #!.

this is what I used as reference

it says it can be scpt an the first line would help determine which kind of script it is

I wrote that post, but if I were you, I'd listen to @peternlewis. He wrote KM, so I think he might know a little more than I do. :roll_eyes:

yeah
changing the extension made it work.
thanks both for your time :smiley:

2 Likes

If you are comfortable with it, then please share your plugin once it is done.

@JMichaelTX, @ccstone. Might this post be suitably moved to the Questions and Suggestions category, as it's seeking help and advice rather than publishing a plug-in ?

Sorry if I'm talking rubbish, in which case I'll bin this comment.

2 Likes