OT - getting the computer's name under OSX

Ken Ray kray at sonsothunder.com
Thu Sep 16 09:40:32 EDT 2004


On 9/16/04 8:14 AM, "Ken Ray" <kray at sonsothunder.com> wrote:

> On 9/16/04 4:52 AM, "Terry Judd" <tsj at unimelb.edu.au> wrote:
> 
>> I know I can get the user's name under OSX by querying $user, but how
>> do I get hold of the computer's name (as given in the Sharing
>> preferences pane).
> 
> Here you go:
> 
> on mouseUp
>   answer ComputerName()
> end mouseUp
> 
> function ComputerName
>   local tName
>   put shell("system_profiler SPSoftwareDataType") into tData
>   get matchText(tData,"(?s)Computer Name:\W*(.*?)\n",tName)
>   if it is true then
>     return tName
>   else
>     return "Error: Can't locate computer name."
>   end if
> end ComputerName

Now that I'm thinking about it, there's a much easier way:

function ComputerName
  set the itemDel to ":"
  return (item 1 of the address)
end ComputerName

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list