How to get the value of variables inside itemScript ??

I am not able to show the value of a variable in a button. The code I am using is:

on itemScript(itemUUID)
set xX to get_string_variable "CubaseEventRenamer_Name"
return "{BTTMenuItemText: '" & xX & "'}"
end itemScript

The button shows "e2 {...".

But if I change the 2nd line to set xX to "HELLO" the button shows HELLO correctly.

How do I get the value of the variable ? What I am doing wrong?

BetterTouchTool executes these Apple Scripts just like the system script editor would do. This means if you call BTT functionality you still need to include the "tell application BetterTouchTool" parts.

For your example:

on itemScript(itemUUID)
	
	tell application "BetterTouchTool" to set xX to (get_string_variable "CubaseEventRenamer_Name")
	return "{BTTMenuItemText: '" & xX & "'}"
	
	
end itemScript

If you instead switch the script type to "real javascript" you could do this in a much more readable way:

async function itemScript(uuid) {
	let name = await get_string_variable("CubaseEventRenamer_Name")
	return `{BTTMenuItemText: '${name}'}`
}

1 Like

Thans @Andreas_Hegenberg
It works perfect.

If I put the following code in the applescript section, the script returns the value of xX:

set xX to get_string_variable "CubaseEventRenamer_Name"
return xX
on itemScript(itemUUID)
return "{BTTMenuItemText: 'Hello'}"
end itemScript

So, it seems that including "tell application BTT" is only necessary inside the handler "on intemScript", isn't it?

I'm curious. Why this difference?

that’s interesting, maybe the function creates a new context that’s not aware that it is by BetterTouchTool. I’ll investigate a bit.

1 Like