HashTag Macro KM 7.0

This is My first Macro to post here and I'm very weak in Applescript But this works...
I like to hashTag a lot and this Macro is a big help to me... Thank you KM!


Applescript code:

choose from list {"#AffinityDesigner ", "#DigitalArt ", "#Art", "#KeyboardMaestro ", "#TumultHype ", "#BohemianCodingSketch", "#AffinityPhoto", "#Design", "#Summer", "#Nice", "#draw", "#illustration", "#GraphicDesigner"} with title "HashTag Picker V1.0" with prompt "Select one or more HashTag, will be copied to System clipboard." with multiple selections allowed



File Download:
HashTag V1.0 KM7 .kmmacros (3.6 KB)


However I'm still learning never stopping, Feel free to change and feel free to Criticize or post your tweeks.

Cheers and Regards,
Bill

2 Likes

Nice idea! The one teeny issue I see with that macro is that it's kind of a lot of work to set up more hashtags you want to use. If you want to take a more "Keyboard Maestro-ish" approach, you could look at using a set of text-insert macros. Here's a thought of a slightly different approach:

First, set up a macro group that's triggered when you want to enter hashtags. In this example I'm using CTRL + # . This will pop up a palette of potential hash tags as well as enable typed strings to quickly fill in the hash tag you want.

Then set up typed string triggered macros for each hash tag you want to save. You can save a bit of time by using the %ExecutingMacro% variable so that whatever you name the macro is the hash tag that will be entered. Just duplicate a macro and rename it. You can use short and easy to remember typed strings too since the macro group's only temporarily enabled. No need to worry about overlapping other stuff you'll commonly type.

When you're ready to go, CTRL + #, then type your tags or select them from the palette. When you're done, close the palette.

Alternately, if you don't want the palette, you could just create shortcut strings for each, so you could have "##km" insert "#keyboardmaestro " or something. Lots of options.

3 Likes

WOW Thank you! It’s great and I totally understand now, And you are absolutely right MUCH easier. Will Update this when done…

Once again thank you for the advice.

Bill

My variant on this would be to simply give them all the same hot key and then Keyboard Maestro will display a palette of all your hash tags and you can type a bit of any of them to select them.

3 Likes

Here’s how to improve upon the AppleScript.

It now is type-selectable — and multiple items are supported.

-Chris

set hashTagList to items 1 thru -2 of {¬
  "AffinityDesigner", ¬
  "AffinityPhoto", ¬
  "Art", ¬
  "BohemianCodingSketch", ¬
  "Design", ¬
  "DigitalArt", ¬
  "draw", ¬
  "GraphicDesigner", ¬
  "illustration", ¬
  "KeyboardMaestro", ¬
  "Nice", ¬
  "Summer", ¬
  "TumultHype", ¬
  ""}

tell application (get path to frontmost application as text)
  set myChoice to choose from list hashTagList with title "HashTag Picker V1.0" with prompt "Select one or more HashTag, will be copied to System clipboard." default items {item 1 of hashTagList} with multiple selections allowed
end tell

if myChoice ≠ false then
  repeat with i in myChoice
    set contents of i to "#" & (contents of i)
  end repeat
end if

set AppleScript's text item delimiters to " "

return myChoice as text
1 Like

Wow This works great and Simpler than setting up palette. Though once the palette was configured works very good but allot of work compared to the script. Love them both and both have good benefits.
I really like both and will use both for now…

Again Thank you very much you guys are so kind to help out. :smile:

I was wondering is it possible to make this with check Box? for one hand operation.
I did research and found a lot of nothing…

Again Big Thank you.

Bill

Hey Bill,

That could probably be done with Pashua or ASObjC, but it starts getting complicated.

Keyboard Maestro can do checkboxes in its User-Input Action, but again you add complexity.

-Chris

1 Like

You can use a prompt for user input for checkboxes, but it’ll require manually adding new fields for each checkbox. Not ideal.

The palette’s the closest thing you’ll get without some substantial interface work. Not exactly the same as a checklist but it lets you click multiple items one-handed and insert each one.

1 Like

I’d love to see someone build this with the Custom HTML Prompt action. It would take more work to setup, although if the checkboxes were added via JavaScript, once done it would be a simple array to add entries to (like @ccstone’s AppleScript hashTagList).

I’d do it myself, but I’m a little busy right now!

1 Like

I've been enjoying messing with HTML prompts, so I thought I'd take a stab at this. As with all my JXA and JavaScript, it's pretty fugly, but it does what it needs to do - takes a comma-delimited list of hashtags and creates an HTML prompt with checkboxes for your tags, then pushes those back out to a variable.

Peter, one oddity I ran into is in the inserting the checkboxes variable by JavaScript. When I put them in there, they're automatically set to checked, even though that isn't the value in the variable. If I add a delay with setTimeout prior to inserting the checkboxes, that doesn't happen. Not sure if this is a bug or if it's how JS works, but it was strange.

It would also be fantastic if it were possible to just insert a variable into an HTML prompt without JavaScript. Just %Variable%Foo% like you can in other text fields.

HTML Prompt Checkboxes.kmmacros (5.6 KB)

3 Likes

Nothing fugly that I can see : - )

FWIW, mileage may vary, but I personally find it quicker (in terms of scripter time) to use .map(), which skips past having to set up and keep an eye on various variables and iterators etc.

e.g., perhaps:

function run() {
    var kme = Application('Keyboard Maestro Engine');

    return kme.variables['hashtags'].value()
        .split(',')
        .map(function (x) {
            var cbVal = x.trim();

            return '<label><input type="checkbox" name="checkbox" value="' +
                cbVal + '" data-ignore></input>' + cbVal +
                '</label>\n<br />';
        })
        .join('\n');
}
1 Like

I write my JXA like I write my AppleScript. Not up on all the JS functions. Need to look into map, I think.

1 Like

iNik, many thanks for sharing this macro. :+1:

It has really helped me understand how to dynamically update the HTML code from KM and JXA.

@peternlewis:
I agree with this request.
That would make it so easy to make dynamic HTML prompts.
Hopefully it would work with both text in the Action, and in a referenced HTML file.

Rob, thanks for sharing this great piece of JXA script.

I can use it directly, and as a model for dynamically building other parts of the HTML code for the HTML prompt Action.

Very cool macro!

I couldn’t duplicate this so I don’t really know what you mean. But Keyboard Maestro is going to try to go through your fields and configure them itself, but exactly when that happens compared to when your code is executing is hard to know.

It calls a function KMInit() before filling in the fields, so that may be the place you want to do your work. I have added for the next version calls to KMWillShowWindow() and KMDidShowWindow() which may be useful in the future.

1 Like

Peter, I’m not sure I fully understand your suggestion.

@iNik’s current HTML code:

window.onload = function() {

	window.setTimeout(appendCheckboxes,0);
	
}

So, are you suggesting that it should be:

function KMInit() {
	appendCheckboxes();
}

Yeah… I can’t duplicate it either anymore.

KMInit and window.onload seem to run at about the same time. I was testing them both out to see if they changed the buggy behavior (it had no affect). Very odd.

And yes, JMichaelTX, that would be how you’d want to write up the JS.

Thanks iNik.

Just tested using the KMInit(), and it worked fine.
The checkboxes were NOT checked.

I’m working on some enhancements for the Custom HTML Prompt action, and I’ve thought about this but I don’t think I’ll do it. HTML is far too complex to safely parse, so I can’t just run the text token expansion over it. At most I could perhaps special case %Variable%Whatever%, but even that is pretty ugly. What happens when your variable has quotes in it, or HTML, should it just be inserted verbatim? That could lead to some very weird behaviour.

It’s easy enough to use boilerplate code in the KMInit to extract a variable (or any tokenised text) and put it as the value of an element, and then you know exactly what is going to happen.

Keep in mind too that Keyboard Maestro will fill in fields with the matching variable values when you create the Custom HTML Prompt window (as shown in the example in the Macro Library).