Skip to content

Instantly share code, notes, and snippets.

@jdleslie
Last active February 9, 2024 18:41
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save jdleslie/9a3566037e35437a3846c428f306318f to your computer and use it in GitHub Desktop.
Save jdleslie/9a3566037e35437a3846c428f306318f to your computer and use it in GitHub Desktop.
Map Apple modifiers (Ctrl, Option, Command) to Windows modifiers (Ctrl, Win, Alt) in Citrix Workspace using Karabiner Elements, with working Alt+Tab and Windows key shortcuts
{
"title": "Citrix Receiver/Workspace modifiers for Ctrl, Alt, Windows order",
"rules": [
{
"description": "In Citrix, add fn modifier to tab so it is forwarded",
"manipulators": [
{
"from": {
"key_code": "tab",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "tab",
"modifiers": [ "fn" ]
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}, {
"description": "In Citrix, change left_option to Alt key via \"⌘⌥ Command (left)-Option\"",
"manipulators": [
{
"from": {
"key_code": "left_option",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "left_option",
"modifiers": [ "left_command", "fn" ]
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}, {
"description": "In Citrix, change right_option to Alt key via \"⌘⌥ Command (left)-Option\"",
"manipulators": [
{
"from": {
"key_code": "right_option",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "right_option",
"modifiers": [ "left_command", "fn" ]
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}, {
"description": "In Citrix, change left_command as well via \"Send Windows logo key using ⌘ Command (right)\"",
"manipulators": [
{
"from": {
"key_code": "left_command",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "right_command"
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}
]
}
{
"title": "Citrix Receiver/Workspace modifiers for Ctrl, Windows, Alt order",
"rules": [
{
"description": "In Citrix, add fn modifier to tab so it is forwarded",
"manipulators": [
{
"from": {
"key_code": "tab",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "tab",
"modifiers": [ "fn" ]
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}, {
"description": "In Citrix, change left_command to Alt via \"⌘⌥ Command (left)-Option\"",
"manipulators": [
{
"from": {
"key_code": "left_command",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "left_command",
"modifiers": [ "left_option" ]
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}, {
"description": "In Citrix, change right_command to Alt via \"⌘⌥ Command (left)-Option\"",
"manipulators": [
{
"from": {
"key_code": "right_command",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "left_command",
"modifiers": [ "left_option" ]
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}, {
"description": "In Citrix, change left_option to Windows logo key via \"Send Windows logo key using ⌘ Command (right)\"",
"manipulators": [
{
"from": {
"key_code": "left_option",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "right_command"
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}, {
"description": "In Citrix, change right_option to Windows logo key via \"Send Windows logo key using ⌘ Command (right)\"",
"manipulators": [
{
"from": {
"key_code": "right_option",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "right_command"
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
]
}
]
}
]
}
]
}
{
"title": "Home/End mapping compatible with Citrix Receiver/Workspace",
"rules": [
{
/* In Citrix, the Windows remote handles this combination natively */
"description": "Except in Citrix, change Control-Home to navigate to top of document via Command-Up",
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
],
"type": "frontmost_application_unless"
}
],
"from": {
"key_code": "home",
"modifiers": {
"mandatory": [
"control"
],
"optional": [
"shift"
]
}
},
"to": [
{
"key_code": "up_arrow",
"modifiers": [
"left_command"
]
}
],
"type": "basic"
}
]
},
{
/* ibid */
"description": "Except in Citrix, change Control-End to navigate to bottom of document via Command-Down",
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
],
"type": "frontmost_application_unless"
}
],
"from": {
"key_code": "end",
"modifiers": {
"mandatory": [
"control"
],
"optional": [
"shift"
]
}
},
"to": [
{
"key_code": "down_arrow",
"modifiers": [
"left_command"
]
}
],
"type": "basic"
}
]
},
{
/* Fn-Left/Right maps to Home/End in Citrix, making it a better choice than Command-Left/Right for Citrix users.
MacOS supports Home/End functionality in two ways:
* Command-Left/Right: Maps to Control-Left/Right in Citrix (useless), behaves as expected in MacOS
* Fn-Left/Right: Maps to Home/End correctly in Citrix, behaves as expected in MacOS
Reference: https://www.cnet.com/how-to/two-mac-keyboard-shortcuts-for-missing-home-and-end-keys/
*/
"description": "Change Home to navigate to start of line via Fn-Left (Fn-Left maps to Home in Citrix)",
"manipulators": [
{
"from": {
"key_code": "home",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "left_arrow",
"modifiers": [
"fn"
]
}
],
"type": "basic"
}
]
},
{
/* ibid */
"description": "Change End to navigate to end of line via Fn-Right (Fn-Right maps to End in Citrix)",
"manipulators": [
{
"from": {
"key_code": "end",
"modifiers": {
"optional": [
"any"
]
}
},
"to": [
{
"key_code": "right_arrow",
"modifiers": [
"fn"
]
}
],
"type": "basic"
}
]
}
]
}
{
/* Based on https://gist.github.com/permil/ed5a66f7e0cb712b0a9c03532530b9dd */
"title": "Print Screen mapping compatible with Citrix Receiver/Workspace",
"rules": [
{
"description": "Except in Citrix, change print_screen to capture entire screen via Command-Shift-3",
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
],
"type": "frontmost_application_unless"
}
],
"from": {
"key_code": "print_screen"
},
"to": [
{
"key_code": "3",
"modifiers": [
"left_command",
"left_shift"
]
}
],
"type": "basic"
}
]
},
{
"description": "Except in Citrix, change print_screen to capture current window via Command-Shift-4",
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.citrix\\.XenAppViewer$",
"^com\\.citrix\\.receiver\\.icaviewer\\.mac$"
],
"type": "frontmost_application_unless"
}
],
"from": {
"key_code": "print_screen",
"modifiers": {
"mandatory": [
"option"
]
}
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 50
},
"to": [
{
"key_code": "4",
"modifiers": [
"left_command",
"left_shift"
]
}
],
"to_delayed_action": {
"to_if_invoked": [
{
"key_code": "spacebar"
}
]
},
"type": "basic"
}
]
}
]
}
@jdleslie
Copy link
Author

jdleslie commented May 31, 2020

Overview

For mysterious reasons the Citrix Receiver/Workspace MacOS client works great for Ctrl, but is missing the most obvious choices for mapping Alt and Windows logo key modifiers. There is the appearance of configurability in the preferences, but the choices available do not to allow users who are already fluent in Windows and Excel keyboard shortcuts to have a normal experience. The available choices either require either additional modifier keys to be pressed or the use of modifier keys on the right of the space bar. (keys foreign to many ANSI users)

Adding more obvious mappings addresses almost all the issues around the Alt and Windows logo key modifiers for me. The mappings here work with Karabiner Elements (previously Karabiner and KeyRemap4Macbook).

It would be much better to have these options alongside the existing options in Citrix Workspace, but until then this works for me and perhaps for you as well.

Feel free to leave comments and feedback!

Usage

  1. Place files in ~/.config/karabiner/assets/complex_modifications
  2. In Karabiner-Elements Preferences window select Complex modifications tab and click Add rule button
    image
  3. Pick a key order and enable rules.
    • Don't enable both Ctrl, Alt, Windows and Ctrl, Windows, Alt or the first enabled layout will take preference
    • Key order refers to the left-to-right ordering of modifier keys on the bottom left of the keyboard.
      • Most Windows laptops are Ctrl, Windows, Alt (sometimes with an interrupting Fn key)
      • Labels on some keyboards make more sense as Ctrl, Alt, Windows (e.g. when Option says "Alt" on the keycap)
        image
  4. Verify that Citrix Workspace is configured appropriately. The following Citrix Workspace (version 2005) settings work with this configuration:
    image
  5. Enjoy

References

Citrix

Karabiner Elements

@antongorshkov
Copy link

This is really great! I've been struggling with this for a while and it solves all my problems so far. Thanks!

P.S. would be great to see it as part of standard modification library - not sure how I stumbled on this, but it took a while to find.
https://ke-complex-modifications.pqrs.org/?q=Alt

@jdleslie
Copy link
Author

jdleslie commented Dec 4, 2020

Thanks for the suggestion. I'll take a look at mainlining it. I had to update the above configs as a recent update to Citrix Workspace changed its MacOS bundle identifier to com.citrix.receiver.icaviewer.mac

@jdleslie
Copy link
Author

jdleslie commented Dec 7, 2020

Submitted PR to merge this modification

@antongorshkov
Copy link

Thanks for updating the bundle identifier - was wondering why this stopped working after Citrix upgrade - all good now.

@jdleslie
Copy link
Author

jdleslie commented Dec 10, 2020

Thanks for updating the bundle identifier - was wondering why this stopped working after Citrix upgrade - all good now.

👍

Submitted PR to merge this modification

PR was merged, so modification is now part of the Karabiner library.

@honvl
Copy link

honvl commented Apr 1, 2021

I have a Ctrl Windows Alt keyboard, but somehow the Ctrl Alt Windows rules worked correctly for me. Also, on a new install of Karabiner Elements, I had to restart the Citrix Client before Karabiner could bind to it and make these modifications work.

@damianzawadzki
Copy link

Hi, everything as expected, but because of right command is the Windows logo there is no way to switch from Citrix Workspace to the other app within macOS using CMD+TAB, but it is only the little discomfort.

@antongorshkov
Copy link

Hi, everything as expected, but because of right command is the Windows logo there is no way to switch from Citrix Workspace to the other app within macOS using CMD+TAB, but it is only the little discomfort.

The workaround I have is I use Right-Shift+I for chrome inside MacOS, so I normally switch to that to get out of Citrix and then Alt-Tab works fine. Also, for frequently used MacOS apps, I have a number of Right-Shift shortcuts like that, this minimizes the need for having alt-tab altogether.

@haithan58
Copy link

It was useful. Thank you so much.

@simrigh
Copy link

simrigh commented Jan 4, 2022

Hi there, thanks so much for sharing this! I haven’t tried it but it looks great!

I’ve been livings with whatever Citrix on my Mac has to offer for my connection to a Win virtual machine, until I’ve realized what brought me here actually… Namely, how to emulate Win+Tab? With that checkbox “Send Windows logo…” selected, I can indeed trigger the Win/Start button alone on the remote Windows box, but… whenever I follow up with the Tab, the Mac’s standard App Switcher kicks in!!! This happens despite I’m inside a Citrix session/connection. Almost as if that Cmd+Tab (that should be translated to Win+Tab when reaching the Windows box via Citrix) was never making past Mac OS that happily launches its App Switcher first and doesn’t bother passing it on to Citrix. Note: in Windows 10, Win+Tab is a different story than Alt+Tab, so this is actually a very relevant case… (Alt+Tab works flawlessly for me).

Any ideas how to get hold of/transmit Win+Tab without the Mac’s App Switcher “intercepting” it, please?

I’ve done some research, and it looks like there’s no way of telling Mac OS to change the keyboard shortcut that launches the App Switcher, it’s gotta be Cmd+Tab, apparently … I’ve also tried disabling that checkbox mentioned above and send “Windows logo key” by mapping some other key (e.g. left shift) to left_gui and/or right_gui (which, according to some folks on the internet, should correspond to the Win key on a Windows machine), but this didn’t work either, and I always end up with the App Switcher overtaking. Also, disabling Cmd+Tab conditionally only in Citrix - i.e. mapping the combination to a virtually key None - is pointless, because while it doesn’t trigger the Mac’s App Switcher in Citrix indeed, it doesn’t trigger just anything (tightly so, it’s mapped to a None after all…)

@raneenmoves
Copy link

Hi! This is awesome thanks! Any idea how to use ALT for other shortcut functions? E.g. Excel Group / Ungroup shortcut is ALT+SHIFT + Left/Right Arrow - This doesn't seem to work anymore once I updated my mac and trying to map it from the windows keyboard to citrix receiver.

@QuantumHawk
Copy link

QuantumHawk commented Jan 9, 2022

Hi! can you help me make it work?
My issue is I use left control instead left command in my mac
but after that, left control become a Win button in citrix. But it has to work like a control!
so ctrl+c/ctrl+V is not working
I need a rule when left control will work in citrix like in mac..

Monosnap 2022-01-06 23-39-51

```

{
"title": "Citrix Receiver/Workspace modifiers for Ctrl",
"rules": [
{
"description": "Ctrl",
"manipulators": [
{
"from": {
"key_code": "left_control",
"modifiers": { "optional": [ "any" ] }
},
"to": {
"key_code": "left_command",
"modifiers": { "optional": [ "any" ] }
},
"type": "basic",
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\.citrix\.XenAppViewer$",
"^com\.citrix\.receiver\.icaviewer\.mac$"
]
}
]
}
]
}
]
}

@oxblood8
Copy link

oxblood8 commented May 1, 2022

Hi there. So I am new to the Macos world, coming from 20+ years of Windows dev. I am using Citrix daily for work and thank you for the wonderful scripts above, massive help.

However, within Macos I have switched the Command/Control keys to make it more Windows (damn muscle memory). When I do this, it throws off the commands within Citrix (Left Control key is what is triggering Windows start button, not the windows key).

Therefore I am wondering is there a way to update the JSON files to account for the Control/Command swap within Macos?

@jdleslie
Copy link
Author

jdleslie commented May 2, 2022

Hi there. So I am new to the Macos world, coming from 20+ years of Windows dev. I am using Citrix daily for work and thank you for the wonderful scripts above, massive help.

However, within Macos I have switched the Command/Control keys to make it more Windows (damn muscle memory). When I do this, it throws off the commands within Citrix (Left Control key is what is triggering Windows start button, not the windows key).

Therefore I am wondering is there a way to update the JSON files to account for the Control/Command swap within Macos?

You might try to update the value of key_code value in from and reload the rules in Karabiner. Here is a list of key codes: https://github.com/JoshuaManuel/Karabiner-Elements-Key-List

Mapping a mapped key sounds fragile, but will probably work.

@denisula
Copy link

Hi! can you help me make it work? My issue is I use left control instead left command in my mac but after that, left control become a Win button in citrix. But it has to work like a control! so ctrl+c/ctrl+V is not working I need a rule when left control will work in citrix like in mac..

Monosnap 2022-01-06 23-39-51
> {
> "title": "Citrix Receiver/Workspace modifiers for Ctrl",
> "rules": [
> {
> "description": "Ctrl",
> "manipulators": [
> {
> "from": {
> "key_code": "left_control",
> "modifiers": { "optional": [ "any" ] }
> },
> "to": {
> "key_code": "left_command",
> "modifiers": { "optional": [ "any" ] }
> },
> "type": "basic",
> "conditions": [
> {
> "type": "frontmost_application_if",
> "bundle_identifiers": [
> "^com\.citrix\.XenAppViewer$",
> "^com\.citrix\.receiver\.icaviewer\.mac$"
> ]
> }
> ]
> }
> ]
> }
> ]
> }

I have same question

@peterminlee
Copy link

I have a question on the Alt function. It seems that after applying this script, my "Alt" gets triggered if I hold down the Option button but not as a single click. For example, when I am in Excel on Citrix, I would normally run Excel shortcuts by clicking Alt + X + X (i.e. Alt-H-I-C to add a new column). However, because I have to hold Option for Alt to trigger, I can't run these shortcuts. Any advice on how to make this work?

@GeorgeCas
Copy link

GeorgeCas commented Aug 30, 2022

This is beautiful, chef's kiss. Makes using Citrix on my Mac so much nicer. I find it best to just double tap the window so it's maximised but not fullscreen and then it's easy to hop around in and out the session.

Makes me actually want to use my MacBook for programming on the go through Citrix. The only criticism I have is for Citrix themselves not offering all this functionality as standard through their app.

@airstrike
Copy link

airstrike commented Mar 6, 2023

I have a question on the Alt function. It seems that after applying this script, my "Alt" gets triggered if I hold down the Option button but not as a single click. For example, when I am in Excel on Citrix, I would normally run Excel shortcuts by clicking Alt + X + X (i.e. Alt-H-I-C to add a new column). However, because I have to hold Option for Alt to trigger, I can't run these shortcuts. Any advice on how to make this work?

I realize it's been almost a year since you asked this, but I had the exact same issue. I solved it by removing the , "fn" modifier from lines #38 and #62 in the gist above. I also never needed to add the rule called "add fn modifier to tab so it is forwarded". I've made these edits in a forked gist to make your life easier in case you're interested

FYI I have also add a few rules under "Simple modifications" which make life easier. Here's a screenshot in case you'd like to copy them:

image

@airstrike
Copy link

This is beautiful, chef's kiss. Makes using Citrix on my Mac so much nicer. I find it best to just double tap the window so it's maximised but not fullscreen and then it's easy to hop around in and out the session.

Makes me actually want to use my MacBook for programming on the go through Citrix. The only criticism I have is for Citrix themselves not offering all this functionality as standard through their app.

Can't you just use Cmd+Tab to alt-tab out of the full screen Citrix window and Option+Tab as "Alt+Tab" within Citrix? That's how I roll

@GeorgeCas
Copy link

Can't you just use Cmd+Tab to alt-tab out of the full screen Citrix window and Option+Tab as "Alt+Tab" within Citrix? That's how I roll

Yeah, I have it setup to work that way too and it's nice. For whatever reason I still just keep it as a maximised window, I like having the Mac top toolbar visible. Also respect for responding to the year old query of the other guy ;)

If OP sees this then again, chef's kiss, I daily your config for work purposes.

@stephenharper82
Copy link

Thank you so much for sharing this. Straightforward instructions and worked first time! Looking forward to using my Mac for my day job now! :D

@stephenharper82
Copy link

What key combination gets a '#' please?

@stephenharper82
Copy link

I've been able to workaround the above by disabling the rules for the right hand side of the keyboard and using opt + 3 as normal.

I am struggling to get the equivalent of hodling ALT and selecting text to select a rectangular block. Using my mapped to alt opt key results in a right click most of the time (I have seen it do a block select twice and I can't figure out why). Any ideas?

@den3erw
Copy link

den3erw commented Jun 30, 2023

Is there any way to restrict these key maps to Citrix? I am also seeing these changes throughout MacOS.

@oxblood8
Copy link

oxblood8 commented Jul 1, 2023

@den3erw Yes you can limit this to just Citrix. In the scripts you will see the following:

"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\.citrix\.XenAppViewer$",
"^com\.citrix\.receiver\.icaviewer\.mac$"
]
}
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment