Page 1 of 1
Population of a PullDownMenu with USB Port Names
Posted: Mon Mar 01, 2010 3:29 pm
by Redlance305
After two hours of googlin' and searching the runrev sites, I've been unable to find an example of how to populate a pull down menu with available USB/Serial Ports. How do we get a hardware list of ports to populate such a list? (Mostly for the Mac)
Hard coded list:
/dev/cu.usbserial-A9006LdD
/dev/cu.Bluetooth-PDA-Sync
/dev/cu.ARDUINOBT-BluetoothSeri-1
-
/dev/cu.modem
However I need one with devices currently plugged in.
Thanks
~David
Re: Population of a PullDownMenu with USB Port Names
Posted: Mon Mar 01, 2010 4:11 pm
by bn
Re: Population of a PullDownMenu with USB Port Names
Posted: Wed Mar 03, 2010 6:01 pm
by NoN'
Hello David,
On Mac you can use with advantage the BSD commands.
Under Revo, these commands are accessible via the function :
shell ()
Here is a script which allows to get back the list of the active ports such as it appears in " informations system ".
The ideal being to launch the script at the opening of the stack.
Code: Select all
on openstack
set cursor to busy
put "put return & shell (" & quote & "system_profiler SPNetworkDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPIDEDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPSCSIDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPUSBDataType" & quote & ") after resum" & quote into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPFireWireDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPAirPortDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPModemDataType" & quote & ") after resum" into lacomm
do lacomm
sort resum
repeat with i = the number of lines in resum down to 1
if char 1 of line i of resum is not " " then next repeat
if char 1 to 5 of line i of resum = " " then
exit repeat
else
if "Hardware" is in line i of resum then
next repeat
end if
if "modem" is in line i of resum then
put word 1 of line i of resum after portList
put return after last char of portList
next repeat
end if
delete char 1 to 4 of line i of resum
put line i of resum after portList
put return into last char of portList
end if
end repeat
delete last char of portList
put "Choose a port" & return & "-" & return & portList into btn "ThePorts"
end openstack
[/size]
The last part of this code just extract the type of the existing ports and bring it to a button with pull down menu. But a lot of other informations are accessible via the "system_profiler" command. By exemple, with the "SPUSBDataType" argument :
USB Bus:
Vendor Name: Apple Computer, Inc.
Product ID: 32773 ($8005)
Speed: Up to 12 Mb/sec
Bus Power (mA): 500
U3 Smart Drive:
Capacity: 974.5 MB
Drive Type: CD-ROM
Removable Media: Yes
Detachable Drive: Yes
BSD Name: disk3
OS9 Drivers: No
Product ID: 7760 ($1e50)
Speed: Up to 12 Mb/sec
Vendor Name: EMTEC
Bus Power (mA): 500
Serial Number: 070007771FB00018
With the hope it will help you.
regards,
renaud
Re: Population of a PullDownMenu with USB Port Names
Posted: Mon Aug 14, 2017 7:52 pm
by vascoribeiro
Hi!
Reviving this thread

I'm having trouble trying to figure out how to make this pull down menu not with the USB port names but with the "BSD Device Name". This way it would be easier to select the right port to connect with an arduino for example.
Any suggestions?
Thanks!
NoN' wrote:Hello David,
On Mac you can use with advantage the BSD commands.
Under Revo, these commands are accessible via the function :
shell ()
Here is a script which allows to get back the list of the active ports such as it appears in " informations system ".
The ideal being to launch the script at the opening of the stack.
Code: Select all
on openstack
set cursor to busy
put "put return & shell (" & quote & "system_profiler SPNetworkDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPIDEDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPSCSIDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPUSBDataType" & quote & ") after resum" & quote into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPFireWireDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPAirPortDataType" & quote & ") after resum" into lacomm
do lacomm
put "put return & shell (" & quote & "system_profiler SPModemDataType" & quote & ") after resum" into lacomm
do lacomm
sort resum
repeat with i = the number of lines in resum down to 1
if char 1 of line i of resum is not " " then next repeat
if char 1 to 5 of line i of resum = " " then
exit repeat
else
if "Hardware" is in line i of resum then
next repeat
end if
if "modem" is in line i of resum then
put word 1 of line i of resum after portList
put return after last char of portList
next repeat
end if
delete char 1 to 4 of line i of resum
put line i of resum after portList
put return into last char of portList
end if
end repeat
delete last char of portList
put "Choose a port" & return & "-" & return & portList into btn "ThePorts"
end openstack
[/size]
The last part of this code just extract the type of the existing ports and bring it to a button with pull down menu. But a lot of other informations are accessible via the "system_profiler" command. By exemple, with the "SPUSBDataType" argument :
USB Bus:
Vendor Name: Apple Computer, Inc.
Product ID: 32773 ($8005)
Speed: Up to 12 Mb/sec
Bus Power (mA): 500
U3 Smart Drive:
Capacity: 974.5 MB
Drive Type: CD-ROM
Removable Media: Yes
Detachable Drive: Yes
BSD Name: disk3
OS9 Drivers: No
Product ID: 7760 ($1e50)
Speed: Up to 12 Mb/sec
Vendor Name: EMTEC
Bus Power (mA): 500
Serial Number: 070007771FB00018
With the hope it will help you.
regards,
renaud
Re: Population of a PullDownMenu with USB Port Names
Posted: Mon Aug 14, 2017 11:53 pm
by NoN'
Hi Vasco,
After seven years of reflection, I can tell you that the solution was already in my precedent post...
Try that :
Code: Select all
on mouseUp
set cursor to busy
put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum" into lacomm
do lacomm
set itemdelimiter to ":"
repeat with i = 1 to the number of lines in resum
if line i of resum contains "BSD name" then
put last item of line i of resum & return after ron2
end if
end repeat
delete last char of ron2
put "Choose a port" & return & "-" & return & ron2 into btn "ThePorts"
end mouseup
Hope it will help
regards,
renaud
Re: Population of a PullDownMenu with USB Port Names
Posted: Tue Aug 15, 2017 12:31 am
by vascoribeiro
It really was but I'm quite dumb, I'm sorry... And thank you for your help!
In fact, I'm not a programmer and I still have some doubts of how this code works, but I do know enough to "tinker" pieces of code. For example what you gave me didn't work at first, but I was ready for this possibility. It works if I do this changes:
Code: Select all
put "put shell (" & quote & "system_profiler SPNetworkDataType" & quote & ") into resum" into lacomm
do lacomm
and
Code: Select all
if line i of resum contains "BSD Device Name" then
put last item of line i of resum & return after ron2
end if
It shows a little more stuff than I wanted but the name is there, so I have now a way to work it out.
Thank you so much!
NoN' wrote:Hi Vasco,
After seven years of reflection, I can tell you that the solution was already in my precedent post...
Try that :
Code: Select all
on mouseUp
set cursor to busy
put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum" into lacomm
do lacomm
set itemdelimiter to ":"
repeat with i = 1 to the number of lines in resum
if line i of resum contains "BSD name" then
put last item of line i of resum & return after ron2
end if
end repeat
delete last char of ron2
put "Choose a port" & return & "-" & return & ron2 into btn "ThePorts"
end mouseup
Hope it will help
regards,
renaud
Re: Population of a PullDownMenu with USB Port Names
Posted: Tue Aug 15, 2017 2:36 am
by NoN'
Don't be sorry and bravo, it's a beautiful transformation for a "non programmer"!
Have a good day.
renaud
Re: Population of a PullDownMenu with USB Port Names
Posted: Tue Aug 15, 2017 2:46 pm
by Klaus
Hi friends,
why not just:
Code: Select all
...
## put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum" into lacomm
## do lacomm
put shell ("system_profiler SPUSBDataType") into resum
...
?
Best
Klaus
Re: Population of a PullDownMenu with USB Port Names
Posted: Tue Aug 15, 2017 5:54 pm
by vascoribeiro
NoN' wrote:Don't be sorry and bravo, it's a beautiful transformation for a "non programmer"!
Have a good day.
renaud
Thank you Renaud!

Using your code I got to another way of doing what I wanted again, I think it is a simpler way, so I'll leave here... It can be useful for other noobs like me!
Code: Select all
set cursor to busy
put shell ("ls /dev/cu.*") into resum
put "Choose a port" & return & "-" & return & resum into btn "ThePorts"
Best regards,
Vasco
EDIT
Klaus wrote:Hi friends,
why not just:
Code: Select all
...
## put "put shell (" & quote & "system_profiler SPUSBDataType" & quote & ") into resum" into lacomm
## do lacomm
put shell ("system_profiler SPUSBDataType") into resum
...
?
Best
Klaus
Thank you Klaus, I think my tinker spirit got me to a similar conclusion.
Best regards,
Vasco
Re: Population of a PullDownMenu with USB Port Names
Posted: Tue Aug 15, 2017 9:09 pm
by NoN'
Hi Klaus,
Because of the beauty of course
No, you are absolutly right I don't remember the reason why I used this structure in my initial post seven years ago, but there is no reason here.
Thank you for this simplification.
Best
Renaud