# How to connect to Mainframe from your Mac laptop using x3270

In order to connect to Mainframe you need to have a 3270 terminal emulator. There are variety of options you can choose from. Unfortunately some of those options still lack the support for macOS Catalina.

I have been using WineHQ to run my favorite Windows based 3270 terminal emulator thanks to Petr Plavjaník and his post: Running Your Windows 3270 Mainframe Emulator on macOS.

Unfortunately, WineHQ does not have support (October 29, 2020) for macOS Catalina yet. I had to look for a different tool to connect to mainframe. The easiest seemed to be just to grab a x3270 and use it. There was a little bit more to make the user experience better and following steps can help with it.

These steps were tested on macOS Catalina 10.15.7.

## 1. Install Homebrew

Homebrew is a Package Manager for macOS.

UPDATE 11/26/2021: Thanks to Lukas Zima, who found that the original Homebrew install command is no longer working on newer macOS versions. The bellow command was successfully tested on macOS Monterey 12.0.1.

`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`

## 2. Install x3270

x3270 is an IBM 3270 terminal emulator.

`brew install x3270`

What might surprise you — definitely surprised me — is that the Homebrew x3270 package does not contain a x3270 executable. The ‘x’ in the name indicates X Window System which is a windowing system common on Unix-like operating systems. However no longer common on macOS. Because of this, the Homebrew x3270 package no longer comes with the x3270 X Window System executable. It comes with c3270 instead.

## 3. Run c3270

c3270 is an interactive 3270 emulator that runs on a character-mode terminal and it can run on a macOS terminal window too.

Open your terminal and issue following command that will turn it into a 3270 terminal:

`c3270 mainframe.host.com`

At this point you should have a working 3270 emulator on your Mac laptop. If you want to make your user experience a little bit better, you might want to follow these additional steps.

## 4. Bigger terminal resolution

First you need to change resolution of the native terminal application. Start the Terminal application. In Terminal menu select Preferences… and there under Profiles select your default profile and change to Window tab where you can increase the Window Size. I use 160x50 which doubles the standard resolution and adds 2 more lines for top menu line and bottom status line of c3270 application.

Start your terminal with updated profile and run c3270 with additional parameters:

`c3270 -model 3279-5 -oversize 160x48 mainframe.host.com`

## 5. Custom keymap

c3270 includes a compiled-in definition for the default keymap, called base. You can view the default mapping by hitting **Ctrl+n** in c3270 terminal and selecting Display Keymap from the File menu. Alternatively start c3270 without any parameters and from the c3270 prompt line then issue **show(keymap)**.

`[base:1] Ctrl<Key>]: Escape()`

[base:2] Escape: Escape()

[base:3] Ctrl<Key>A Ctrl<Key>A: Key(0x01)

[base:4] Ctrl<Key>A Ctrl<Key>]: Key(0x1d)

[base:5] Ctrl<Key>A <Key>c: Clear()

[base:6] Ctrl<Key>A <Key>e: Escape()

[base:7] Ctrl<Key>A <Key>i: Set(insertMode,true)

[base:8] Ctrl<Key>A <Key>r: Reset()

[base:9] Ctrl<Key>A <Key>k: Keypad()

[base:10] Ctrl<Key>A <Key>l: Redraw()

[base:11] Ctrl<Key>A <Key>m: Compose()

[base:12] Ctrl<Key>A <Key>n: Menu()

[base:13] Ctrl<Key>A <Key>p: PrintText()

[base:14] Ctrl<Key>A <Key>q: Quit()

[base:15] Ctrl<Key>A <Key>^: Key(notsign)

[base:16] <Key>DC: Delete()

[base:17] <Key>UP: Up()

[base:18] <Key>DOWN: Down()

[base:19] <Key>LEFT: Left()

[base:20] <Key>RIGHT: Right()

[base:21] <Key>HOME: Home()

[base:22] Ctrl<Key>A <Key>1: PA(1)

[base:23] Ctrl<Key>A <Key>2: PA(2)

[base:24] Ctrl<Key>A <Key>3: PA(3)

[base:25] <Key>F1: PF(1)

[base:26] Ctrl<Key>A <Key>F1: PF(13)

[base:27] <Key>F2: PF(2)

[base:28] Ctrl<Key>A <Key>F2: PF(14)

[base:29] <Key>F3: PF(3)

[base:30] Ctrl<Key>A <Key>F3: PF(15)

[base:31] <Key>F4: PF(4)

[base:32] Ctrl<Key>A <Key>F4: PF(16)

[base:33] <Key>F5: PF(5)

[base:34] Ctrl<Key>A <Key>F5: PF(17)

[base:35] <Key>F6: PF(6)

[base:36] Ctrl<Key>A <Key>F6: PF(18)

[base:37] <Key>F7: PF(7)

[base:38] Ctrl<Key>A <Key>F7: PF(19)

[base:39] <Key>F8: PF(8)

[base:40] Ctrl<Key>A <Key>F8: PF(20)

[base:41] <Key>F9: PF(9)

[base:42] Ctrl<Key>A <Key>F9: PF(21)

[base:43] <Key>F10: PF(10)

[base:44] Ctrl<Key>A <Key>F10: PF(22)

[base:45] <Key>F11: PF(11)

[base:46] Ctrl<Key>A <Key>F11: PF(23)

[base:47] <Key>F12: PF(12)

[base:48] Ctrl<Key>A <Key>F12: PF(24)

[base:49] <Key>PPAGE: Scroll(backward)

[base:50] <Key>NPAGE: Scroll(forward)

The easiest way to add your own custom key map is by placing .c3270pro file into your home directory. Here is my own **.c3270pro**:

! Use the 'mine' keymap, defined below

c3270.keymap: mine! Definition of the 'mine' keymap

! U+007F is backspace

c3270.keymap.mine: \

<Key>U+007F: Erase\n\

Ctrl<Key>W <Key>i: ToggleInsert()\n\

Ctrl<Key>W <Key>d: DeleteField()\n\

Ctrl<Key>W <Key>e: EraseEOF()\n\

Ctrl<Key>W <Key>1: Home() String("swap 1") Enter()\n\

Ctrl<Key>W <Key>2: Home() String("swap 2") Enter()\n\

Ctrl<Key>W <Key>3: Home() String("swap 3") Enter()\n\

Ctrl<Key>W <Key>4: Home() String("swap 4") Enter()\n\

Ctrl<Key>W <Key>5: Home() String("swap 5") Enter()\n\

Ctrl<Key>W <Key>6: Home() String("swap 6") Enter()\n\

Ctrl<Key>W <Key>7: Home() String("swap 7") Enter()\n\

Ctrl<Key>W <Key>8: Home() String("swap 8") Enter()\n\

Ctrl<Key>W <Key>n: Home() String("start") Enter()\n\

Ctrl<Key>W <Key>§: Home() String("swap list") Enter()

*I did not figure out how to simply use Ctrl+number. Instead I have to use Ctrl+w as starting modifier followed by the number. If anyone knows how to go around it, please let me know.*

UPDATE 11/9/2020: Thanks to Vít Gottwald I learned that terminals cut 3 higher bits of a character when pressed together with a modifier key (Ctrl or Alt). This is for example why <Ctrl-I> behaves the same as <Tab>. And this is also why I was not able to map <Ctrl-1> because it translates as <Ctrl-Q>. Following article gets you more details if you are interested: Why Ctrl-1 is Not Working in Terminal.

## 6. Making a Dock icon

Start **Script Editor** by typing its name in Spotlight Search (⌘Space) and place following script into it:

**tell** application "Terminal"

**activate**

**do script** "c3270 -model 3279-5 -oversize 160x48 mainframe.host.com"

**end tell**

Test the script by hitting the play icon and once ready save it in Applications as Application file format:

Navigate to Applications using Finder and locate you newly created application. Select **Get Info** from the application context menu or hit ⌘i alternatively to display the info. Click on the icon in top left corner and now you can paste (⌘v) previously copied (⌘c) image as your new icon.

Final bit is to drag the application and drop it on your Dock so you have the 3270 terminal emulator readily available at your mouse click.

## 7. File Transfer

You can transfer files between host and client. Access the top menu of c3270 terminal. You can either press CTRL+n or select it by mouse. Under *File* choose *File Transfe*r.

Note: Mind the note that cursor needs to be positioned on an input field that can accept the IND$FILE command. If in ISPF — best is to choose

6 Commandfor situations when the IND$FILE command might be longer due to parameters.

The process will walk you through handful of questions when at the end the file transfer will initiate.

Few of my resulting IND$FILE sample commands for reference:

`=> IND$FILE PUT petrv.link.load.xmit5 RECFM(F) LRECL(80) SPACE(50,50) TRACKS`

=> IND$FILE PUT petrv.foo' ASCII CRLF

=> IND$FILE PUT link.load5.xmit RECFM(F) LRECL(80)

=> IND$FILE PUT petrv.argo.jcl(foo2) ASCII CRLF RECFM(F) LRECL(80) BLKSIZE(6160)

Happy mainframing!