Set TouchBar to show F-keys?

I maintain an AppleScript application that launches an MS-DOS emulator, and I wonder if the following is possible:

In a new MacBook Pro, I can set the touchbar to display F-keys when my application is running by adding the application to the Function Keys list in the Shortcuts pane of the Keyboard preferences. The app id seems to be saved to ~/Library/Preferences/ (I’m using a borrowed MacBook Pro without Xcode installed, so I have no way of seeing how that plist works).

Is there any way to write the app id and “use function keys” setting to that plist file using AppleScript or a shell script that I could run from AppleScript?

So far, I can’t find any documentation for this, but maybe I’m looking in the wrong places. Thanks for any help.

OK, to refine my question, I see that defaults read on that plist produces this:

PresentationModePerApp =     {
    "org.wpdos.vdoswp" = functionKeys;
    "vDos512901030Wine.wineskin.prefs" = functionKeys;

But I can’t figure out the syntax for adding an entry. Any help gratefully received.

I don’t think it’s really a good idea. If there’s a front-door way of doing it, use that.

My tests using defaults found it unreliable – System Preferences seemed to override the value. My gut feeling is that there’s more to it than that single domain entry.

OK, I’ll see what I can do. I probably should have spelled out the hard part of the problem, which is that the emulator application is stored inside an AppleScript application bundle, so there’s no way for a user to click on it and select it in the Keyboard preference pane.

The only method I’ve found for adding the emulator app to the list of funtion-key apps is to drag a copy out of emulator out of the bundle to someplace accessible like the Desktop, and then select it from there in the Keyboard pane. Then I can delete the copy of the emulator. But that isn’t practical for ordinary users.

Shane, have you figured out how to use the NSTouchBar class to set the touchbar to show the standard function keys? I’m asking the author of Wineskin Winery to add an option to allow that with Wineskin wrappers like the one I’m using. Someone already asked this question on, but didn’t get an answer, and I can’t find one online - but, again, maybe I’m not looking in the right place.

No, I haven’t. I have a horrible feeling they really don’t want you to do that. If you have a developer account, it might be worth burning a support incident on – at the very least, you should log a bug/request.

For what it’s worth, here’s a test for whether touchbar function keys are enabled for a specific application:

set touchBar to true
	set touchBarText to do shell script "ioreg | grep AppleEmbeddedOSSupportHost"
on error
	set touchBar to false
end try
if touchBar is true then
	set fkeysSet to true
		set fkeysSetText to do shell script "defaults read | grep YOUR.APP.PREFS.HERE | grep functionKeys"
	on error
		set fkeysSet to false
	end try
	if fkeysSet is false then display dialog "Follow the instructions, etc."
end if

The problem is that you can actually add entries to – using NSUserDefaults – but they still get ignored. Odd.

[quote=“ShaneStanley, post:6, topic:638, full:true”]
No, I haven’t. I have a horrible feeling they really don’t want you to do that. If you have a developer account, it might be worth burning a support incident on – at the very least, you should log a bug/request.[/quote]

I’ll definitely post a request; I have a developer account, and might as well make use of it. Thanks for the suggestion.

I know this is a years old topic now, but I found it when googling for how to set the Touch Bar per app settings via an AppleScript and found this info useful. Also, I have some more useful info to share.

I found that after you set these preferences with defaults write commands, you can run killall ControlStrip to make them take effect.

I also found that if you want to reset the plist default values with defaults delete that running killall ControlStrip afterward is not enough. But, you can run killall TouchBarServer as sudo or with administrator privileges via AppleScript (since it’s a root process) to force the Touch Bar to fully reload and the default settings will then take effect after running defaults delete

PS. Entries can be added to the “PresentationModePerApp” key with the following command:
defaults write PresentationModePerApp -dict-add com.comany.AppName functionKeys

PPS. You can also set per app Touch Bar settings to more than just functionKeys with this technique, which I don’t think is possible through any GUI:
defaults write PresentationModePerApp -dict-add com.comany.AppName fullControlStrip

@Pico - Thank you for this. It is exactly what I was looking for years ago.

EDIT: And the code I posted above doesn’t work in the OS that I’m testing at the moment. But:

ioreg | grep TouchBarServer

does seem to indicate the presence or absence of the TouchBar.

And I’m fairly sure the answer is “No”, but here’s the question:

Has anyone found a way to use a shell script or AppleScript to switch System Preferences - Keyboard - Keyboard - “Touch Bar shows” to “F1, F2 keys, etc.” without turning on GUI scripting??

Again, for security reasons, the answer is almost certainly No, but if anyone has found a way to do this, they’re probably reading this forum.