Work in progress and alpha features

let result = await runAppleScript({script: "presetfile://MCC/as/some.scpt"})

let actionDefinition = {
    "BTTPredefinedActionType" : 172,
    "BTTPredefinedActionName" : "Run Apple Script (blocking)",
    "BTTAppleScriptFilePath" : "presetfile://MCC/as/some.scpt"",
};
let result = await callBTT('trigger_action', {json: JSON.stringify(actionDefinition)});

using preset paths for applescripts would be useful :slight_smile: any guides for this

also i couldn find a way for activate btt then highlight a btt trigger ( with given UUID ) with applescript, i can guide user to related trigger when they want to change a setting

Good idea, I don't think it's curently possible to show/highlight a specific trigger but I can definitely add that.

Currently the runAppleScript function wants the Apple Script as string, not the path to the script. However you could use the run shellScript function like this:

( async ()=> {


let shellScriptWrapper = {
    script: 'osascript "BTT_PRESET_PATH/some.scpt"', // mandatory
    launchPath: '/bin/bash',
	   parameters: '-c'
 
};

let result = await runShellScript(shellScriptWrapper);


returnToBTT(result);

})()

This uses osascript to execute the scpt file.

thanks for guide, yes its working in btt window but when i try in floating window, i cant run script from file. its working when i put full path

I believe it's the same issue that I've encountered the other day. BTT_PRESET_PATH is not escaping spaces properly in AppleScript, \ is needed before spaces whereas only one \ is present.

Andreas said it would be fixed in next alpha, stay tuned :wink:

Oh I think I actually didn't see your edit where you reported that issue :slight_smile: My reply was to the other point :slight_smile:

To get the path escaped use BTT_PRESET_PATH_ESCAPED. Usually you can also just wrap the path that contains spaces in quotes. The situation where spaces are currently not supported is when running shell scripts and using the BTT_PRESET_PATH variable in the parameter field, which is kind of a special case.

I just test it in applescript widget:

return "BTT_PRESET_PATH_ESCAPED"

And I get the following result:

ah the script result view is not showing escapes

Maybe post a script and I'll tell you how to make it work. Here is one stupid example:

my problem is my script working on btt interface as you suggested but not working on floating web view

this one working on web view
osascript "/Users/xxx/Library/Application\ Support/BetterTouchTool/PresetBundles/57FD4165-C9CC-4D74-ADF4-6DEE2C49A7D9MCC/MCC/as/CalendarYearView.scpt"

but these two didnt work
osascript "BTT_PRESET_PATH_ESCAPED/MCC/as/CalendarYearView.scpt"
osascript "BTT_PRESET_PATH/MCC/as/CalendarYearView.scpt"

I was able to reproduce the webview issue, this will be fixed with the next version!

1 Like

thats great, i can put all applescripts to one place now, will be easier to find them now, thanks :wink:

3.358 adds Clipboard Manager / Java Script Text Transformer functions:
http://docs.bettertouchtool.net/docs/8c_text_transformer_functions.html

They can be pretty cool:

3 Likes

This is amazing, I never knew I was waiting for this feature!

1 Like

This looks great so far! I also like the buttons on the side of the Clipboard manager as opposed to the dropdown before. I've two questions regarding this:

  1. Can this be used to replace a lot of Automator/AppleScript Services from years ago which perform similar text modifications? Does it have performance implications?
  2. With the Services, one didn't need to use the clipboard but just operate on text which was selected. I use Launchbar along with BTT which also allows picking up any object File/Folder/SelectedText/etc. and run scripts over it. Could BTT be instead made to operate on selected objects like that instead of first putting them in Clipboard? This could allow storing all scripts in BTT itself as opposed to some in Launchbar and some in Automator.

I would expect performance to be better than automator / apple scripts because no extra process needs to be started.

You can already run scripts on selected text without explicitly using the clipboard, however in the background BTT still uses the clipboard. I plan to integrate a service that can access the selected text, so the clipboard becomes obsolete soon.

In the latest alpha I also added a "Transform Selected Text using Java Script" action which is a bit easier to use than the Insert / Type / Paste action.

2 Likes

Updating to the latest alpha broke this existing piece of code which used to work earlier.

    tell application "BetterTouchTool"
	update_trigger "C32910A2-2203-474A-A2A3-AF65A0B87183" json "{\"BTTEnabled2\" : 1}"
    end tell

I use it to enable/disable media controls in certain apps automatically when they activate. The same code works fine in Script editor but doesn't work either automatically in BTT or even clicking Run manually.

Weird could you check whether the UUID is still correct? (in the alpha I have a database cleanup job which should remove duplicate UUIDs, which should not exist in the first place )

Yes, I checked the exact code in AppleScript Editor and it both enables/disables the button fine.
I also checked if "Specific app did activate" works by enabling the HUD and the HUD is triggered but the script fails.

1 Like

Maybe for some reason the apple script runner processes are not launched. I'll check if I broke something! (maybe you can check whether activity monitor shows the BetterTouchToolAppleScriptRunner processes)

Update: I disabled "Run in background" in the script action and now it works again, both when running from the settings as well as automatically as before.