Hi,
Using real javascript blazing fast compared to applescript.
I combined javascript and applescript then made some benchmarks results are very promising. Problem is applescript trying to recompile 500 line of script. i converted all if statements in applescript to javascript then only used applescipt as small scripts and i get 3x speed boost
I will share soon an improved version of "Enhanced Dock" and a script for Finder completely based on javascript
so why not improve javascript integration
here we go probably will add more over time
//works
trigger_named_async_without_response({trigger_name:'swmfloat'})
//BTT crashes
trigger_named_async_without_response('swmfloat')
//works
trigger_named('swmfloat')
//"cancel_delayed" key might be useful for double / triple tap detection etc
//otherwise i have to call twice cancel_delayed_named_trigger_execution({trigger_name:'Action5'})
trigger_named_async_without_response({trigger_name: 'Action5', wait_for_reply: false,delay:1,cancel_delayed:true})
//works
callBTT('cancel_delayed_named_trigger_execution',{trigger_name: singleTapNamedTrigger})
//i guess not working, tried for triple key press
cancel_delayed_named_trigger_execution({trigger_name:'Action5'})
//key trigger
(async()=>{
G=await get_number_variable("OptQtapCount")
C=(G=="")?0:G
set_number_variable("OptQtapCount",C+1)
try{
cancel_delayed_named_trigger_execution({trigger_name:'MultiTapOptQ'})
}catch{}
trigger_named_async_without_response({trigger_name:'MultiTapOptQ',delay:0.5})
returnToBTT(C)
})()
(async()=>{
C=await get_number_variable("OptQtapCount")
set_number_variable("OptQtapCount",0)
if(C==1){
paste_text({text:"Tapped 1"})
}else if(C==2){
paste_text({text:"Tapped 2"})
}else{
paste_text({text:"Tapped 3"})
}
returnToBTT(C)
})()
I ended with this solution
Using parameters instead of object for simple ones would be nice
//works
set_persistent_string_variable({variable_name:'SWM-FA',to:'somevalue'})
//partially works
set_persistent_string_variable('SWM-FA','somevalue')
//not works, you can try with SWM preset folder COM.js > line 19
//it could be related type of c is number if i remember correcly
//i guess you have to check type of parameters for all btt functions
set_persistent_string_variable('SWM-'+k,c)
//works
callBTT('resize_webview',VJ)
//not works in floating webview
resize_webview(VJ)
//works
runShellScript({script:"say hello"})
//not works
runShellScript(`say hello`)
//works
runAppleScript(`beep`)
//works
paste_text({text:"SomeText"})
//not works
paste_text("SomeText")
//Using message variable as number or object instead of string crashing BTT
trigger_action({json:JSON.stringify({
BTTPredefinedActionType:371,
BTTAdditionalActionData:{
BTTActionSendNotificationMessage:message,
BTTActionSendNotificationTitle:"Enhanced Dock",
BTTActionSendNotificationSound:s?"Morse":"Bottle"
}
})})
//coudn't show hud like this on real javascript. not sure what caused this
trigger_action({json:JSON.stringify({
BTTPredefinedActionType:254,
BTTHUDActionConfiguration:{
BTTActionHUDPosition:"6",
BTTActionHUDWidth:"36",
BTTActionHUDHeight:"36",
BTTActionHUDBackground:"0.000000, 0.000000, 0.000000, 153.781290",
BTTActionHUDBlur:"0",
BTTActionHUDDisplayToUse:"1",
BTTActionHUDSlideDirection:"0",
BTTActionHUDHideWhenOtherHUDAppears:false,
BTTActionHUDDuration:"0.15000000596046448",
BTTActionHUDDetail:"x",
BTTActionHUDTitle:"x",
BTTActionHUDAttributedTitle:"x"
}
})})
//works
set_clipboard_content({content:'test',format:'NSPasteboardTypeString'})
//BTT crashes
set_clipboard_content({content:1,format:'NSPasteboardTypeString'})
//not works
set_clipboard_content("test")
Feature requests
Autohotkey like sending keys, also i suggest you to look all their documentation
Im using AHK on windows with depth customizations. i can share my setup or if you need any help on AHK logic i can detail
their layout
alt key > !
shift key > +
ctrl > ^
win > #
tab > {tab}
< or > selects which modifier keys to use
...
Send_Keys("!+{M}")
//they are using sequences like this
Send_Keys("{Ctrl Down}{Alt Down}{M}{Ctrl Up}{Alt Up}{Down 7}{Enter}")
get_menubar_item({item:"(3):item"}) > returns true if exist
get_menubar_item({item:"(3):(2)},status:true) > returns true if enabled
get_menubar_item({item:"(3):(2)},name:true) > returns string of item
support for real javascripts as .js file like applescript
it will be time saver while developing
would be cool if we get related values as object
otherwise i have to call BTT too many times and it slows down script
get_properties_object("mouse_screen")
{x:0,y:0,width:1680,height:1050}
get_properties_object("focused_screen")
{x:0,y:0,width:1680,height:1050}
get_properties_object("visible_frame")
{x:0,y:25,width:1680,height:1025}
get_properties_object("screen")
{
mouse_screen:{
x:0,
y:0,
width:1680,
height:1050
},
focused_screen:{
x:0,
y:0,
width:1680,
height:1050
},
visible_frame:{
x:0,
y:25,
width:1680,
height:1025
}
}
get_properties_object('dist_active_win')
{
x:{top_left:,top_right:,bottom_left:,bottom_right:},
y:{top_left:,top_right:,bottom_left:,bottom_right:}
}
same object logic could be done for hovered_item_details, trackpad, magic mouse, Mouse Position, Mouse Position in window, window... and list goes on
ofc im not sure about performance when you bundle all of it. but still bundling mouse_screen, focused_screen , visible_frame (and maybe a screens object) will be a nice improvement
get_string_variable("active_app_name")
returns "Voice Memos" and its not always usable on some apps even native ones
tell application "Voice Memos" to activate not works because real name is "VoiceMemos" on system. also many apps has this problem
im using like this on most of my scripts. short name works without problems on process scripting
//activating target app before this
runAppleScript(`short name of (info for (path to "egfp"))`)
might be useful if you add
get_string_variable("active_app_shortname")
if i try to use
runAppleScript(`tell app "System Events" to tell window 1 of process (name of app id "`+(await get_string_variable("BTTActiveAppBundleIdentifier"))+`")`
macOS starts to ask btt tries to control .. app
alert("something")
send a notification to system in webview but not in real javascript. that one really helpful while developing.
console.log("something")
also tried console.log but does nothing.
a basic notification system would be cool or a console for real javascript
trigger_action(290)
would be nice shorthand for most functions that not requires additional keys
currently does nothing
Thanks