How to bypass BetterTouchTool capturing a shortcut in AppleScript?

I am trying to define a keyboard shortcut in BTT for the Preview app that maps CMDS to

  • export to PDF if the open file is a PDF file or
  • perform regular save if it isn't.

The AppleScript I have developed for the shortcut looks like this:

tell application "Preview" to set filePath to path of front document
if filePath contains ".pdf" then
	tell application "System Events"
		keystroke "e" using {shift down, command down}
		delay 0.5
		keystroke "g" using {shift down, command down}
		delay 0.1
		key code 51
		keystroke filePath
		key code 76
		delay 0.5
		key code 76
		delay 1.0
		key code 48
		delay 1.0
		key code 49
	end tell
else
	tell application "System Events"
		keystroke "s" using {command down}
	end tell
end if

I like the CMDS shortcut triggered in the else statement to be directly sent to Preview instead of being captured by BTT.

Can I achieve this either by

  • modifying my AppleScript or
  • moving the conditional statement to BTT to only run the script if the file type is PDF?

One solution is to define two triggers, one on key down and another one on key up.

  1. On key down: trigger CMDS key down, pass modifiers if any, and disable recursive triggers
  2. On key up: run the script shared above with the else section completely removed