Link to home
Start Free TrialLog in
Avatar of EndTheFed
EndTheFedFlag for United States of America

asked on

MacOS How to rename attached USB hardware device name such as RS232 Serial Adapter for connecting with screen command?

Hello all

I use the built-in terminal command screen to connect to devices through my FTDI USB to RS232 serial adapter.
It works great and I'm having no functionality issues. To connect I use:
screen /dev/tty.usbserial-AJ03IZPF 9600

It would be nice to not have to enter the serial number each time. Is there a way to rename attached USB hardware so it could be shortened to:
screen /dev/tty.usbserial 9600 or if it has to be unique at the end something like: screen /dev/tty.usbserial-1 9600

MBP 2016, MacOS 10.12.3
Avatar of Eoin OSullivan
Eoin OSullivan
Flag of Ireland image

You're looking to create a symlink or alias?
If the device always mounts with the same name can you just create an alias in your bash script?
As far as I am aware if you create a symlink it will be lost when you reboot but you could try that also.

If the device gets a different name each time you mount it then it is a lot messier as OSX doesn't have udevadm command .. I've seen scripts that use the diskutil command and parsing to extract the identifiers and create a link based on that but to be honest I've never needed or tested a script like that.

Here's an Apple forum discussion on a similar topic for guidance
https://discussions.apple.com/thread/1673329?tstart=0
Avatar of EndTheFed

ASKER

I was hoping to actually rename it if that were possible.

It does always have the same name, the characters after the hyphen is the serial number of the device which won't change. I'm not using a script to run commands, would an alias still work consistently for this situation?
I tried the suggestion from that Apple forum and got an Operation not permitted error.
Since it was from 2008 and OS X has changed considerably since then, including many security improvements, I'm thinking that may be what's preventing it (new permissions settings). Any ideas?

$ sudo ln -s /dev/tty.usbserial-AJ03IZPF /dev/tty0
ln: /dev/tty.usb0: Operation not permitted
SOLUTION
Avatar of Eoin OSullivan
Eoin OSullivan
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Screen is a "windowing" system
Look ls -li /dev | grep tty
See if the USBdevice is referenced as another resource reference the inode

See whether you can alias Using kextutil to define let's say /dev/tty0 when the tty.usbserial-AJ03IZP is attached.
You shouldn't really change the device name as that's part of the device when it's mounted.  It would also be a lot of trouble and would only exist on your system.  You don't actually have to type the entire device name on the bash command prompt.  You can press the tab key as soon as you type the first different character from the other devices.  The tab command completion is built into bash and you can use if for any file or directory path.

screen /dev/tty.usb{Press Tab}
and it should command complete to the following.
screen /dev/tty.usbserial-AJ03IZPF

Then type the 9600 baud after
screen /dev/tty.usbserial-AJ03IZPF 9600

To complete your command, you could type it like the following, using only 19 keystrokes + enter for a total of 20 keys:
scre{tab} /d{tab}tty.u{tab} 9600

You might even be able to get away with 18 keystrokes, less than half of the keys of actually typing the full thing if you don't have other devices plugged in on your system:
scre{tab} /d{tab}tty.{tab} 9600

While you can symlink it, if the device isn't actually connected, then you'll just have a dangling link.  You might as well write a simple script to run load it and have it tell you if the device exists or not.  That would actually be better than having a dangling link.  Neither the script nor symlink are ideal if you plug in multiple devices that use the same name.

Place this code in a file (e.g. usbserial)
#!/bin/bash
if [ -c /dev/tty.usbserial-AJ03IZPF  ]
    screen /dev/tty.usbserial-AJ03IZPF 9600
elif
    echo "Plug in your USB serial cable"
fi

Open in new window


Make the file executable.
chmod +x usbserial

If you don't make it executable, you can just sh usbserialb or bash usbserial
Once you make it executable, you can add your path location to the environment variable or just precede it with ./  (e.g.  ./usbserial ) if you're in the current directory.  You can also place in in /usr/local/bin/ (where user created executable files go).  If you do put it there, you need to make it executable or it won't run if you just type the command.
@Arnold
When I run that command it doesn't look like the USB device is referenced as another resource anywhere in that list.
Could you please walk through the steps of creating an alias using kextutil? That would be different than a symlink as suggested by Eoin OSullivan right?

@Eoin OSullivan
That worked, must be the permissions on the dev folder. I created a new folder at root called 's' (for symlink) and it let me create it there. I imagine as time goes on I'll create other useful symlinks and I'll just keep them all in that folder. Now I only have to type 'screen /s/tty' to connect.

@serialband
Thanks for the tip, I completely forgot about that. Hitting {tab} is a nice shortcut for situations like this. For something I'll be connecting to regularly I'd like to keep the keystrokes as short as possible.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@serialband .. thanks for that .. it was the "alias" I was referring to which is an alternative to a symlink in this case
Those are both pretty slick. It's working with the symlink and the alias now. Thanks!