write text on Touch Bar

at the help of @Mark FX and @Shane Stanley (Thank you) I successfully put text in the menubar using script below. I just wonder if it’s possible to put the same think in the Touch Bar with minor modifications.

thx


use framework "Foundation"
use framework "AppKit"
use scripting additions

property myApp : a reference to current application

property statusBar : missing value
property statusItem : missing value
property statusItemImage : missing value

set statusItemTitle to "Hello World! ⛵️"


set my statusBar to myApp's NSStatusBar's systemStatusBar()

if my NSThread's isMainThread() as boolean then
	my displayStatusItem:statusItemTitle
else
	my performSelectorOnMainThread:"displayStatusItem:" withObject:statusItemTitle waitUntilDone:true
end if

my changeStatusItemTitle:statusItemTitle
delay 3

-- display alert (statusBar's thickness())


repeat
	set statusItemTitle to (time string of (current date))
	my changeStatusItemTitle:statusItemTitle
	delay (1.0)
end repeat

on changeStatusItemTitle:title
	statusItem's button's setTitle:(title)
end changeStatusItemTitle:

on displayStatusItem:title
	set my statusItem to statusBar's statusItemWithLength:(myApp's NSVariableStatusItemLength)
	statusItem's button's setTitle:title
	
	set statusItemMenu to myApp's NSMenu's alloc()'s initWithTitle:""
	
	set quitMenuItem to myApp's NSMenuItem's alloc()'s initWithTitle:"Quit" action:"quitStatusItem" keyEquivalent:"q"
	quitMenuItem's setTarget:me
	
	statusItemMenu's addItem:quitMenuItem
	
	statusItem's setMenu:statusItemMenu
end displayStatusItem:

on quitStatusItem()
	set quitStatusItem to button returned of (display alert "Do you want to quit the status bar item ?" buttons {"NO", "YES"})
	if quitStatusItem = "YES" then
		my removeStatusItem()
		tell me to quit
	end if
end quitStatusItem


on removeStatusItem()
	statusBar's removeStatusItem:statusItem
end removeStatusItem

-- And Add This Function

on quit {}
	continue quit
end quit

([applescript] posting tag corrected by NG.)

I found a link below but not really understand.
Touch Bar GUI Scripting Demo
https://lists.apple.com/archives/applescript-users/2017/Apr/msg00070.html

That link is not about creating a touch bar application, but is about how to GUI script a touch bar application, which is a big difference.

You can script other applications like “Finder” or “Safari” and loads of others, and you can do whats called GUI scripting, which is the same as clicking buttons and other UI elements within applications with AppleScript code, which is what that linked article is all about.
But to be clear, that GUI scripting code has nothing to do with actually creating an application with an NSTouchBar feature.
For that you should be Googling NSTouchBar application tutorials and examples, if you plan on on attempting such an application in AppleScriptObjC, you would have to convert any suitable tutorials Swift or ObjectiveC code into AppleScriptObjC code, which is something people here might be able to help with.

So it is not as simple as merely placing your NSStatusBar code into an NSTouchBar application, there very different types of app.
I personally wouldn’t attempt an NSTouchBar application from the Script Editor, that’s not to say it couldn’t be done, but testing and debugging such an app project would be a nightmare.
And is something I personally would only undertake from Xcode, which in itself has a big learning curve.
Also who ever was going to be able to help with with coding such an app, that person would need a Apple laptop with a Touch Bar, which I don’t have, but I’m sure many others here do have.

But for the moment, Apple has some documentation related to the NSTouchBar class.
https://developer.apple.com/documentation/appkit/nstouchbar
https://developer.apple.com/documentation/appkit/touch_bar/creating_and_customizing_the_touch_bar
These pages will give you some idea of what’s involved with such an application.
And you will find many other tutorials online as well, which will also inform you as to what’s involved.

Regards Mark

Thanks @Mark FX. Let me look at the documents.