My apple script to automate preset export/backup process. Might be useless if you solely rely on cloud sync. I do local backups. Few caveats.

Sharing my own apple script to automate the hideous preset export process.

Few caveats:

  • BTT config window must be open and in front.
  • I didn't automate choosing between "Triggers only" and "Triggers and Settings" because somehow, the apple script takes too long to trigger the action. I still haven't figured out this part.

The automation:
If front window is BTT, export highlighted (my only preset), manually choose "triggers and settings", input folder export path, input additional text after default name, save and overwrite.

It might be too clunky, and noncustomizable if you are are new to applescript, but I googled my entire way through. Now I don't have to click all those buttons to export.

How I use this:

  • Add BTT on sidebar, and make a new trigger (key sequence for me).
  • Action: run apple script (async)

If you know a way to open BTT config using a shortcut or automation, pls let me know so I can include it in the script.

Script:

#BTT must be front before running script
#because I haven't figured out how to automate launching BTT config

tell application "System Events"
	
	#Check if BTT is front
	set activeApp to name of first application process whose frontmost is true
	if "Bettertouchtool" is in activeApp then
		#Start export automation
		click menu bar item "Presets" of menu bar 1 of application process "BetterTouchTool" of application "System Events"
		delay 0.2
		click menu item "Export Preset" of menu "Presets" of menu bar item "Presets" of menu bar 1 of application process "BetterTouchTool" of application "System Events"
		delay 0.5
		click button "Export Highlighted" of pop over 1 of checkbox "Preset: edlim ▾" of window "BetterTouchTool" of application process "BetterTouchTool" of application "System Events"
		#manually click TRIGGERS & SETTINGS
		
		#wait for Finder window "Save"
		repeat until (exists window "Save" of application process "BetterTouchTool" of application "System Events")
			delay 0.2
		end repeat
		delay 0.3
		
		#Findow window has appeared, open export location
		keystroke "G" using {command down, shift down} --go to folder
		delay 0.2
		keystroke "~/google drive/storage" --put your own export path
		keystroke return
		
		#Saving file
		delay 0.3
		--Edit name to "fileName automated backup", e.g. "default.bttpreset" will become "default automated backup.bttpreset"
		key code 124
		key code 49
		keystroke "automated backup"
		keystroke return
		delay 0.5
		
		#If prompts to overwrite filename
		if exists (window "Save" of application process "BetterTouchTool" of application "System Events") then
			click button "Replace" of sheet 1 of window "Save" of application process "BetterTouchTool" of application "System Events" --overwrite
		else
			delay 0.1
		end if
	else
		display dialog ("Open BTT config first.") --reminds you that this will only run when you are in the BTT configuration window
	end if
end tell

Ah BTT already has a function to export a preset by name via Apple Script, it's just not publicly exposed yet. If you need that I'll make it public with the next update.

It will be more reliable and doesn't need the preferences window open. This is how it works:

tell application BetterTouchTool

export_preset NameOfThePreset includeSettings true compress true outputPath "~/Documents/preset.bttpreset" comment "someComment" link "someLink"

end tell

Yes pls I've had so much headache making this work.

It's included in 3.804 alpha which is currently uploading.

Here a full example:

tell application "BetterTouchTool"
	
	export_preset "stream-deck-examples" outputPath "~/Documents/preset.bttpreset" comment "someComment" link "https://someLinkToShowWhenImporting" with includeSettings and compress
	
end tell

Hello Andreas and paki,

I wonder if your solution could help with a related question about exporting/importing presets. I recently acquired a second laptop and immediately set up BTT on it. Since I seem to be one of the few people who love the Touch Bar—a fact I credit entirely to BTT--I added a .bttpreset present file to migrate my numerous actions and settings to the new device.

Unfortunately the BTT path to AppleScripts that I activate via the Touch Bar seems to be absolute, so I need to set different paths for my two devices. This seems a good use case for saving two presets, but when I try to export my existing .bttpreset and re-import into my other device, BTT stops me with the warning "Previous versions of this preset could cause conflicts." It also seems that BTT won’t let me import without deleting old copies, which of course defeats the purpose in my case.

Any recommendations for how to "clone" BTT settings across devices in cases like mine greatly appreciated!

@jonippolito you can put the Apple Scripts into your preset's data folder:

I appreciate the prompt reply, @Andreas_Hegenberg. I will explore this option in the future. (In the meantime, I re-set the paths on my new device just so I could get things working.)

Can you clarify how the Export/Import Present option is supposed to work? I tried that as well, but for some reason the exported preset had minimal information in it.

Thanks!

Presets contain all the triggers configured in BTT (and files if they are located in the preset data folder). Maybe you exported the wrong one?

Ah, probably my error then. I'm an avid BTT user and am sure I'll have more questions in the future. Keep up the good work!

Hello again.

I don't quite understand how exporting all my settings into a present into a certain folder works. The script you provided gave some errors, and also, when I go to presets>open data folder..>myPreset the folder is empty. I only have 1 preset containing everything so it can't be a naming error.

What I want to do is automate the exporting of my settings preset into a folder that I want, instead of doing all those clicks (export highlighted etc).

Which version are you on? This script only works on the latest ones.

I am on this version:
BetterTouchTool 3.826 (July, 28, 2022)

Hi I am on v3.826
the script errors out

BetterTouchTool got an error: "Global" doesn’t understand the “export_preset” message.

And you have a preset that is named „Global“? What exact command did you execute?

Hi Andreas
Its strange, after a reboot-> no error
I do have a preset "Global"

Just wondering if a command exists Or a way to list all triggers & actions for a preset ?

Thank you

I also get this error. I dont understand the other commands like LINK and COMMENT and stuff. I just want the presets exported simply. Export all settings as presetName in finderLocation.

Any text will do fine for link and comment.

Possibly also try to restart your machine, sometimes macOS doesn't update the scripting definitions immediately. Also make sure you don't have an older version of BTT somewhere on your Mac.

Hi. It works now! Thank you. I don;t know but I guess the restart fixed it.