How to retrieve persistent variable value from AS?

Question mostly for @Andreas_Hegenberg because I'm not sure if I'm doing something wrong, or its a bug.
Via webserver API, i can successfuly retrieve persistent string value of name bttStarCount.

However, from AS I keep getting the error: https://i.imgur.com/31q6BV1.png

tell application "BetterTouchTool"
	return get_string_variable "bttStarCount"
end tell

What am I doing wrong? Also if someone can help, how can i concatenate the strings in AS? So the touchbar widget would get Btt: <VALUE THAT I TRIED TO RETRIEVE> ?

Thanks in advance!

1. Concatenation Operator, &

If, for example, you have stringA and stringB and you wish to join them together, the & is the concatenation operator when used on items of class text or string (both equate to the same class):

set stringA to "Hello"
set stringB to "World"

stringA & stringB
    --> "HelloWorld"

Here, the two strings are glued together as they are, without any changes or additions to the final output. If you wanted to insert a piece of text between the two strings in order to separate them, you can either use another concatenation like so:

stringA & " " & stringB --> "Hello World"

2. Text Item Delimiters

Or, you can utilitise an AppleScript property called text item delimiters that serves to both insert a delimiting character between lists of text items during their concatenation; but also to split text at every occurrence of the delimiting character(s):

set my text item delimiters to " "
{stringA, stringB} as text
    --> "Hello World"

Note here that the text item delimiters are acting on a list containing two text items (stringA and stringB), and converting the list into a unary string (text) value.

The default setting for text item delimiters is the empty string, "", such that, ordinarily, lists of text items are joined exactly as they would be if you use the & operator. The & never uses a delimiter.

Say, however, the space between the two strings ought to, instead, be a comma-space:

set my text item delimiters to space
set stringList to the text items of "Hello World"
    --> {"Hello", "World"}

set my text item delimiters to ", "
stringList as text
    --> "Hello, World"

In the above example, the " " representation of the space character was replaced with an AppleScript constant space, which equates to the same value.

Other character constants include tab, linefeed (new line: "\n"), and return (new line: "\r").

If you make use of text item delimiters, bear in mind they will remain set at the value last assigned to them until they are changed again. Some people like to set and reset their text item delimiters immediately after utilising them. Personally, I do not. But as long as you know how to keep track of them, it's a non-issue.

1 Like