Could we get a bit more informations about Simple JSON Format and BTTActions
like a properly JSDoc or at least a type definition. I was trying hard to insert a seperator to my custom menu
. If someone else is facing this issue:
[
{ "title": "1st Item" },
{ "title": "---" },
{ "title": "2st Item" }
]
@Andreas_Hegenberg feel free to contact me to support you for free with JS stuff
I'm with BTT since a decade
If i was too stupid to find the informations I want to apologize in advance.
hehe yes, this "Simple JSON Format" is really new and I haven't decided on all the things yet. The --- was something I added during testing but am not yet sure whether it will stay or whether it will be replaced by some other way to specify item types. Let's see!
I'm working on the docs & examples for this!
1 Like
Follow up question: BTTActions.listOfAppleShortcuts(): ShortcutDefinition[]
the icon
property wich is a base64 string is allways the same
so it does not reflect the real shortcut icon, the color
is correct (even so hex string would be easer ;))

If the stuff is still "experimental" just let me know and I try to practice patience.
unfortunately Apple doesn't provide a way to retrieve the real icons from shortcuts. This can only be done for the glyphs but not for any pixel graphic
In general all functions in "BTTActions" are internally used Swift or Objective-C functions in BetterTouchTool. I expose them to Java Script because some of them can be useful, but most of them have never been tested in JS so they might or might not work 
This one is e.g. used for the BTT action picker
Could you provide some reference? So i would not have to guess so much
I would then like to provide a types.d.ts
to the community with JSDoc, so development of the scripts would become more straight forward.
1 Like
unfortunately there is no usable reference for BTTActions.
Maybe at some point I'll go through it and see what is usable outside of BTT's internal code, but currently nothing like that exists. Many types used in the functions don't even translate to JS.
1 Like
Didn't tested every single function yet (~200) but most seem to be callable exept the following:
bl
clipboardDump
clipboardLock
clipboardString
currentClipboardPasteString
currentClipboardPasteStrings
currentShortcutsMenu
dataProvided
goBackScript
goForwardScript
hideAllScript
lastBlockAction
lastPastedText
mainPasteboard
previousChatGPTRequests
screencaptureConfigWC
systemEventsApp
windowMovingA
windowResizingA
wiSwiWin
1 Like
I have created a basic d.ts definition for the Simple Format, I haven't tested it yet.
declare module "SimpleFormat" {
// Represents attributed text, which can be a simple string or an object with styling.
export type AttributedText =
| string
| {
text: string;
color?: RGBAColor;
size?: string;
};
// Represents the possible item types, matching the Swift enum.
export type SimpleFormatItemType =
| "standard"
| "separator" //requires BTT 4.805, in previous versions set the title of an item to ---
| "back" //floating menu only
| "textField" //floating menu only
| "slider"; //floating menu only
// Represents the definition of an icon, which can be specified in various ways.
export interface IconDefinition {
type: "sfsymbol" | "path" | "base64";
value?: string; // For 'sfsymbol' type.
path?: string; // For 'path' type.
base64?: string; // For 'base64' type.
weight?: string; // Applicable for 'sfsymbol'.
size?: number; // Applicable for 'sfsymbol'.
colors?: RGBAColor[]; // Applicable for 'sfsymbol'.
background?: RGBAColor;
width?: number;
height?: number;
}
// Represents a variable setting action.
export interface SetVariableDefinition {
name: string;
value: string;
}
// Base interface for actions that can have a 'setvariable' property.
interface BaseAction {
setvariable?: string | SetVariableDefinition;
}
// Action type for executing BTT scripts.
export interface BTTAction extends BaseAction {
btt: string;
input?: any;
args?: any;
json?: any;
}
// Action type for triggering named triggers in BTT.
export interface NamedAction extends BaseAction {
named: string;
}
// Action type for triggering actions by UUID in BTT.
export interface UUIDAction extends BaseAction {
uuid: string;
}
// Action type for executing JavaScript code.
export interface JSAction extends BaseAction {
js: string;
}
// Action type for performing keyboard shortcuts.
export interface KeyboardAction extends BaseAction {
keyboard: string;
}
// Action type for running Shortcuts app shortcuts.
export interface ShortcutAction extends BaseAction {
shortcut: string;
input?: string;
}
// Defines the action, which can be a string, an action definition, or an array of actions.
export type Action =
| string
| ActionString
| ActionDefinition
| (string | ActionString | ActionDefinition)[];
// Union type of all possible action definitions.
export type ActionDefinition =
| BTTAction
| NamedAction
| UUIDAction
| JSAction
| KeyboardAction
| ShortcutAction;
export type ActionCategory =
| "standard"
| "hover"
| "longpress" //not yet supported
| "touchrelease" //not yet supported
| "hoverend"
| "hyperkeyrelease" //not yet supported
| "rightclick"
| "changetofalse" //not yet supported
| "appear"
| "disappear"
| "ondrop";
export interface SimpleFormatItemBase {
title?: string | AttributedText;
meta?: string; // some meta information, can e.g. used when filtering searchable list
type?: SimpleFormatItemType;
submenu?: SimpleFormatItemBase[];
background?: string;
icon?: string | IconDefinition;
actions?: { [key in ActionCategory]?: Action }; // this can be used if an item supports more than one action category
action?: Action;
setvariable?: string | SetVariableDefinition;
}
export interface SimpleFormatItemChooseFromList extends SimpleFormatItemBase {
subtitle?: string | AttributedText;
}
// Represents a single item in the format, with all possible properties.
export interface SimpleFormatItemFloatingMenu extends SimpleFormatItemBase {
width?: number;
height?: number;
templateitemuuid?: string; // defines the base item to use as template
}
// The root format is an array of SimpleFormatItems.
export type SimpleFormat = SimpleFormatItemBase[];
// these are attempts at defining the string based definitions
type Digit = `${number}`;
type Whitespace = " " | "";
type Comma = `${Whitespace},${Whitespace}`;
export type RGBAColor =
`rgba(${Whitespace}${Digit}${Whitespace}${Comma}${Digit}${Whitespace}${Comma}${Digit}${Whitespace}${Comma}${Digit}${Whitespace})`;
// Type representing known icon types.
type IconType = "sfsymbol" | "path" | "base64";
// Type representing known icon keys.
type IconKey =
| "weight"
| "color"
| "background"
| "size"
| "width"
| "height";
// Type representing a key-value pair in icon strings.
type IconKeyValuePair = `::${IconKey}@@${string}`;
// Icon string pattern with up to 5 key-value pairs.
export type IconString =
| `${IconType}::${string}`
| `${IconType}::${string}${IconKeyValuePair}`
| `${IconType}::${string}${IconKeyValuePair}${IconKeyValuePair}`
| `${IconType}::${string}${IconKeyValuePair}${IconKeyValuePair}${IconKeyValuePair}`
| `${IconType}::${string}${IconKeyValuePair}${IconKeyValuePair}${IconKeyValuePair}${IconKeyValuePair}`
| `${IconType}::${string}${IconKeyValuePair}${IconKeyValuePair}${IconKeyValuePair}${IconKeyValuePair}${IconKeyValuePair}`;
// Type representing known action types.
type ActionType = "btt" | "keyboard" | "js" | "uuid" | "named" | "shortcut";
// Type representing known action keys.
type ActionKey = "input" | "function" | "args" | "json";
// Type representing a key-value pair in action strings.
type ActionKeyValuePair = `@@${string}`;
// Action string pattern with optional key-value pair.
export type ActionString =
| `${ActionType}::${string}`
| `${ActionType}::${string}${ActionKeyValuePair}`;
}
2 Likes