I've found a solution by combining Better Touch Tool and @Francois answer. It's possible to use a single shortcut that inspects the active element and triggers shortcut A if there is some text selected, and shortcut B if there isn't.
This example relies on having associated ⌘x
with the native Cut action in Xcode and ⇧⌘x
with Cut Current Line
in the mentioned answer.
- In BTT, add an Xcode override (the left panel)
- Select Keyboard Shortcuts (the top panel)
- Create a new keyboard shortcut, e.g.
⌘x
- Add a new block in the right panel, and leave it as "No Action" and selected.
- Paste this there:
[
{
"BTTActionCategory" : 0,
"BTTIsPureAction" : true,
"BTTPredefinedActionType" : 330,
"BTTPredefinedActionName" : "If Condition",
"BTTIfConditionFormat" : "focused_element_details CONTAINS \"AXSelectedText (W): \\\"\\\"\"",
"BTTIfConditionData" : "YnBsaXN0MDDUAQIDBAUGBwpYJHZlcnNpb25ZJGFyY2hpdmVyVCR0b3BYJG9iamVjdHMSAAGGoF8QD05TS2V5ZWRBcmNoaXZlctEICVRyb290gAGvEBYLDBMYICorLTQ4PT5BRUlOT1JYXGBiVSRudWxs0w0ODxAREl8QF05TQ29tcG91bmRQcmVkaWNhdGVUeXBlXxAPTlNTdWJwcmVkaWNhdGVzViRjbGFzcxABgAKAFdIUDxUXWk5TLm9iamVjdHOhFoADgBTUDxkaGxwdHh9fEBFOU1JpZ2h0RXhwcmVzc2lvbl8QEE5TTGVmdEV4cHJlc3Npb25fEBNOU1ByZWRpY2F0ZU9wZXJhdG9ygBOADoAEgBHVISIjJA8lJicoKVlOU09wZXJhbmReTlNTZWxlY3Rvck5hbWVfEBBOU0V4cHJlc3Npb25UeXBlW05TQXJndW1lbnRzgAaABRADgAiADVx2YWx1ZUZvcktleTrSIw8QLIAH0i4vMDFaJGNsYXNzbmFtZVgkY2xhc3Nlc18QEE5TU2VsZkV4cHJlc3Npb26jMDIzXE5TRXhwcmVzc2lvblhOU09iamVjdNIUDzU3oTaACYAM0w8jOTo7PFlOU0tleVBhdGiACxAKgApfEBdmb2N1c2VkX2VsZW1lbnRfZGV0YWlsc9IuLz9AXxAcTlNLZXlQYXRoU3BlY2lmaWVyRXhwcmVzc2lvbqM_MjPSLi9CQ15OU011dGFibGVBcnJheaNCRDNXTlNBcnJhedIuL0ZHXxATTlNLZXlQYXRoRXhwcmVzc2lvbqRGSDIzXxAUTlNGdW5jdGlvbkV4cHJlc3Npb27TSiMPS0xNXxAPTlNDb25zdGFudFZhbHVlgA8QAIAQXxAXQVhTZWxlY3RlZFRleHQgKFcpOiAgIiLSLi9QUV8QGU5TQ29uc3RhbnRWYWx1ZUV4cHJlc3Npb26jUDIz1A9TVFVWTExXWk5TTW9kaWZpZXJXTlNGbGFnc15OU09wZXJhdG9yVHlwZYASEGPSLi9ZWl8QFU5TSW5QcmVkaWNhdGVPcGVyYXRvcqNZWzNfEBNOU1ByZWRpY2F0ZU9wZXJhdG9y0i4vXV5fEBVOU0NvbXBhcmlzb25QcmVkaWNhdGWjXV8zW05TUHJlZGljYXRl0i4vRGGiRDPSLi9jZF8QE05TQ29tcG91bmRQcmVkaWNhdGWjY18zAAgAEQAaACQAKQAyADcASQBMAFEAUwBsAHIAeQCTAKUArACuALAAsgC3AMIAxADGAMgA0QDlAPgBDgEQARIBFAEWASEBKwE6AU0BWQFbAV0BXwFhAWMBcAF1AXcBfAGHAZABowGnAbQBvQHCAcQBxgHIAc8B2QHbAd0B3wH5Af4CHQIhAiYCNQI5AkECRgJcAmECeAJ_ApECkwKVApcCsQK2AtIC1gLfAuoC8gMBAwMDBQMKAyIDJgM8A0EDWQNdA2kDbgNxA3YDjAAAAAAAAAIBAAAAAAAAAGUAAAAAAAAAAAAAAAAAAAOQ",
"BTTEnabled2" : 1,
"BTTOrder" : 1076
},
{
"BTTActionCategory" : 0,
"BTTIsPureAction" : true,
"BTTLayoutIndependentActionChar" : "x",
"BTTShortcutToSend" : "56,55,7",
"BTTEnabled2" : 1,
"BTTOrder" : 1077
},
{
"BTTActionCategory" : 0,
"BTTIsPureAction" : true,
"BTTPredefinedActionType" : 333,
"BTTPredefinedActionName" : "Else",
"BTTEnabled2" : 1,
"BTTOrder" : 1078
},
{
"BTTActionCategory" : 0,
"BTTIsPureAction" : true,
"BTTLayoutIndependentActionChar" : "x",
"BTTShortcutToSend" : "55,7",
"BTTEnabled2" : 1,
"BTTOrder" : 1079
},
{
"BTTActionCategory" : 0,
"BTTIsPureAction" : true,
"BTTPredefinedActionType" : 334,
"BTTPredefinedActionName" : "END If Condition",
"BTTEnabled2" : 1,
"BTTOrder" : 1080
}
]
The result should look like this:
Here's the value used in the If clause for focused_element_details
in case you add it manually:
AXSelectedText (W): ""
The If block is the same for all shortcuts, so just copy and paste it.
</dict>
at the end of the plist. You might want to remove that so that people don't accidentally mess up the plist file if they copy the above text.