• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: AppleScript-Users Digest, Vol 7, Issue 435
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AppleScript-Users Digest, Vol 7, Issue 435


  • Subject: Re: AppleScript-Users Digest, Vol 7, Issue 435
  • From: email@hidden
  • Date: Thu, 26 Aug 2010 11:31:41 -0500

Thanks to Mark, Ed and Geoff for their contributions to help fix the script. I ended up using Ed's recommendation this time but I can see as I move forward there will be a need to recognize more then just en0 and en1.


Jeffrey Madson / RR Donnelley Desktop Engineering



email@hidden
Sent by: applescript-users-bounces+jeffrey.madson=email@hidden

08/25/2010 10:01 AM

Please respond to
email@hidden

To
email@hidden
cc
Subject
AppleScript-Users Digest, Vol 7, Issue 435





Send AppleScript-Users mailing list submissions to
                email@hidden

To subscribe or unsubscribe via the World Wide Web, visit
               
http://lists.apple.com/mailman/listinfo/applescript-users
or, via email, send a message with subject or body 'help' to
                email@hidden

You can reach the person managing the list at
                email@hidden

When replying, please edit your Subject line so it is more specific
than "Re: Contents of AppleScript-Users digest..."


Today's Topics:

  1. One more thing... (email@hidden)
  2. Re: One more thing... (Mark J. Reed)
  3. Re: One more thing... (Mark J. Reed)
  4. Re: One more thing... (email@hidden)
  5. Scripting Mail, smart mailbox (Allen Watson)
  6. Re: Sorting a list of records (email@hidden)
  7. Re: Sorting a list of records (Axel Luttgens)
  8. Re: One more thing... (Geoff Graham)
  9. Re: One more thing... (Mark J. Reed)


----------------------------------------------------------------------

Message: 1
Date: Tue, 24 Aug 2010 15:05:25 -0500
From: email@hidden
Subject: One more thing...
To: email@hidden
Message-ID:
                <email@hidden>
               
Content-Type: text/plain; charset="us-ascii"

Several months ago with the help of several posts here I developed this
little script that gives general information about a Mac to aid a remote
help support person. I have run into a little snag with some recent field
testing and that is the script is looking specifically at en0 if you are
using en1 you get the error: get if addr en0 failed (os/kern) failure.

What is the best way to check both ports or 0 and then 1 if there is no
cable in 0 or all possible cards and then just reporting back what it
finds? Thanks for all your help once again!

set macInfo to system info
set macName to computer name of macInfo
set ipAddress to do shell script "ipconfig getifaddr en0"
set userName to long user name of macInfo
set shortUserName to short user name of macInfo
set hostName to host name of macInfo
set userlocale to user locale of macInfo
set bootvolume to boot volume of macInfo
set homeDirectory to home directory of macInfo
set systemVersion to system version of macInfo
set primaryEthernetAddress to primary Ethernet address of macInfo
set CPUtype to CPU type of macInfo
set CPUspeed to CPU speed of macInfo
set Physicalmemory to physical memory of macInfo
set homeDirecory to home directory of macInfo
set networkInfo to do shell script "/usr/sbin/system_profiler" -- get
network info
set AppleScript's text item delimiters to {"Domain Name:"}
try (* get rid of unavailable domain *)
       set macDomainName to paragraph 1 of text item 2 of networkInfo
on error
       set macDomainName to "unknown"
end try
set AppleScript's text item delimiters to {" "}

set userInfo to {}
set the end of userInfo to {"~HELP DESK INFORMATION~"}
set the end of userInfo to {"Computer Name:", macName} as text
set the end of userInfo to {"IP Address:", ipAddress} as text
set the end of userInfo to {"Network Domain:", macDomainName} as text
set the end of userInfo to {"User Name:", userName} as text
set the end of userInfo to {"Short User Name:", shortUserName} as text
set the end of userInfo to {"Host Name:", hostName} as text
set the end of userInfo to {"User Location:", userlocale} as text
set the end of userInfo to {"Boot Volume:", bootvolume} as text
set the end of userInfo to {"Home Directory:", homeDirectory} as text
set the end of userInfo to {"System Version:", systemVersion} as text
set the end of userInfo to {"MAC Address:", primaryEthernetAddress} as
text
set the end of userInfo to {"CPU Type:", CPUtype} as text
set the end of userInfo to {"CPU Speed:", CPUspeed} as text
set the end of userInfo to {"Memory:", Physicalmemory} as text

set AppleScript's text item delimiters to return

set user_info to userInfo as text (* required to get rid of a confusion
upon 'as *)
display alert user_info buttons {"Copy To Clipboard", "OK"} default button
"OK"
if button returned of result = "Copy To Clipboard" then
       set the clipboard to user_info
end if


Jeffrey Madson / RR Donnelley Desktop Engineering






-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.apple.com/mailman/private/applescript-users/attachments/20100824/0975cde3/attachment.html

------------------------------

Message: 2
Date: Tue, 24 Aug 2010 16:34:29 -0400
From: "Mark J. Reed" <email@hidden>
Subject: Re: One more thing...
To: email@hidden
Cc: email@hidden
Message-ID:
                <email@hidden>
Content-Type: text/plain; charset=UTF-8

Well, you can get a list of interfaces with something like this:

set interfacesList to paragraphs of (do shell script "ifconfig | awk
-F: '/^[^\\t]/ {print $1}'")

And then you can loop through them and try to get their addresses:

set interfacesList to (paragraphs of (do shell script "ifconfig | awk
-F: '/^[^\\t]/ {print $1}'"))
set addressesList to {}
repeat with i from 1 to count interfacesList
   set ifName to (get item i of interfacesList)
   try
       set ipAddr to (do shell script ("ipconfig getifaddr " & ifName))
       set end of addressesList to {(get ifName), ipAddr}
   end try
end repeat
addressesList

The above is far from optimally efficient; you could get all the
necessary data by running a single 'do shell script "ifconfig"' and
just parsing the resulting output - but it's relatively
straightforward.

Note, I had to do the repeat as a count and do a "get" into ifName,
instead of just "repeat with ifName in interfacesList" because the end
result always had "item 6 of lo0, gif0, stf0, en0, fw0, en1, en2, en3"
in place of "en1", even if I used "get ifName".  Seems buggish.

On Tue, Aug 24, 2010 at 4:05 PM,  <email@hidden> wrote:
> Several months ago with the help of several posts here I developed this
> little script that gives general information about a Mac to aid a remote
> help support person. I have run into a little snag with some recent field
> testing and that is the script is looking specifically at en0 if you are
> using en1 you get the error: get if addr en0 failed (os/kern) failure.
>
> What is the best way to check both ports or 0 and then 1 if there is no
> cable in 0 or all possible cards and then just reporting back what it finds?
> Thanks for all your help once again!
>
> set macInfo to system info
> set macName to computer name of macInfo
> set ipAddress to do shell script "ipconfig getifaddr en0"
> set userName to long user name of macInfo
> set shortUserName to short user name of macInfo
> set hostName to host name of macInfo
> set userlocale to user locale of macInfo
> set bootvolume to boot volume of macInfo
> set homeDirectory to home directory of macInfo
> set systemVersion to system version of macInfo
> set primaryEthernetAddress to primary Ethernet address of macInfo
> set CPUtype to CPU type of macInfo
> set CPUspeed to CPU speed of macInfo
> set Physicalmemory to physical memory of macInfo
> set homeDirecory to home directory of macInfo
> set networkInfo to do shell script "/usr/sbin/system_profiler" -- get
> network info
> set AppleScript's text item delimiters to {"Domain Name:"}
> try (* get rid of unavailable domain *)
>         set macDomainName to paragraph 1 of text item 2 of networkInfo
> on error
>         set macDomainName to "unknown"
> end try
> set AppleScript's text item delimiters to {" "}
>
> set userInfo to {}
> set the end of userInfo to {"~HELP DESK INFORMATION~"}
> set the end of userInfo to {"Computer Name:", macName} as text
> set the end of userInfo to {"IP Address:", ipAddress} as text
> set the end of userInfo to {"Network Domain:", macDomainName} as text
> set the end of userInfo to {"User Name:", userName} as text
> set the end of userInfo to {"Short User Name:", shortUserName} as text
> set the end of userInfo to {"Host Name:", hostName} as text
> set the end of userInfo to {"User Location:", userlocale} as text
> set the end of userInfo to {"Boot Volume:", bootvolume} as text
> set the end of userInfo to {"Home Directory:", homeDirectory} as text
> set the end of userInfo to {"System Version:", systemVersion} as text
> set the end of userInfo to {"MAC Address:", primaryEthernetAddress} as text
> set the end of userInfo to {"CPU Type:", CPUtype} as text
> set the end of userInfo to {"CPU Speed:", CPUspeed} as text
> set the end of userInfo to {"Memory:", Physicalmemory} as text
>
> set AppleScript's text item delimiters to return
>
> set user_info to userInfo as text (* required to get rid of a confusion upon
> 'as *)
> display alert user_info buttons {"Copy To Clipboard", "OK"} default button
> "OK"
> if button returned of result = "Copy To Clipboard" then
>         set the clipboard to user_info
> end if
>
>
> Jeffrey Madson / RR Donnelley Desktop Engineering
>
>
>
>
>
>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives:
http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>



--
Mark J. Reed <email@hidden>


------------------------------

Message: 3
Date: Tue, 24 Aug 2010 16:42:49 -0400
From: "Mark J. Reed" <email@hidden>
Subject: Re: One more thing...
To: email@hidden
Cc: email@hidden
Message-ID:
                <email@hidden>
Content-Type: text/plain; charset=UTF-8

On Tue, Aug 24, 2010 at 4:34 PM, Mark J. Reed <email@hidden> wrote:
> Well, you can get a list of interfaces with something like this:
>
> set interfacesList to paragraphs of (do shell script "ifconfig | awk
> -F: '/^[^\\t]/ {print $1}'")

or, more simply

set interfacesList to words of (do shell script "ifconfig -l")

R'ing TFM helps...

--
Mark J. Reed <email@hidden>


------------------------------

Message: 4
Date: Tue, 24 Aug 2010 14:36:49 -0700
From: email@hidden
Subject: Re: One more thing...
To: asu users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset="us-ascii"

Nice script.

You may try this:

try
                set ipAddress to do shell script "ipconfig getifaddr en1"
on error
                set ipAddress to do shell script "ipconfig getifaddr en0"
end try


HTH,

ES
On Aug 24, 2010, at 1:05pm, email@hidden wrote:

> Several months ago with the help of several posts here I developed this little script that gives general information about a Mac to aid a remote help support person. I have run into a little snag with some recent field testing and that is the script is looking specifically at en0 if you are using en1 you get the error: get if addr en0 failed (os/kern) failure.
>
> What is the best way to check both ports or 0 and then 1 if there is no cable in 0 or all possible cards and then just reporting back what it finds? Thanks for all your help once again!
>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.apple.com/mailman/private/applescript-users/attachments/20100824/bc847b94/attachment.html

------------------------------

Message: 5
Date: Tue, 24 Aug 2010 18:11:18 -0700
From: Allen Watson <email@hidden>
Subject: Scripting Mail, smart mailbox
To: email@hidden
Message-ID:
                <AANLkTin_6R=email@hidden>
Content-Type: text/plain; charset="iso-8859-1"

I'm looking for a way to open a named smart mailbox in Apple Mail, by
script. Any ideas?

--
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.apple.com/mailman/private/applescript-users/attachments/20100824/46cb0db5/attachment.html

------------------------------

Message: 6
Date: Tue, 24 Aug 2010 21:49:27 -0700
From: "email@hidden" <email@hidden>
Subject: Re: Sorting a list of records
To: Nigel Garvey <email@hidden>
Cc: AppleScript Users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=windows-1252

The merge sort seems more complicated and a lot slower. Am I missing something?

ES
-----------
property sortedList : {}
property calcList : {}
property listToSort : {}
property finalList : {}

set listToSort to {}
repeat with x from 1 to 100
                set myData to random number from 1 to 10
                set the end of listToSort to myData
end repeat
copy listToSort to originalList

set sortAListStart to current date
set sortedLists to SortAList()
set sortAListEnd to current date
set sortAListElapse to sortAListEnd - sortAListStart
set mergeStart to current date
mergeSort(listToSort, 1, -1)
set mergeEnd to current date
set mergeElapse to mergeEnd - mergeStart

on mergeSort(theList, l, r)
                script o
                                 property mainList : theList -- The list to be sorted.
                                 property extract : missing value -- Holder for extracts from the list
                                 
                                 -- Recursively merge-sort the section of the list between items l and r.
                                 on msort(l, r)
                                                  -- Recurse to sort the left and right halves of this section.
                                                  set m to (l + r) div 2
                                                  if (m > l) then msort(l, m)
                                                  if (r > m + 1) then msort(m + 1, r)
                                                 
                                                  -- The left and right halves are now sorted. Extract a copy of the whole section.
                                                  set o's extract to items l thru r of o's mainList
                                                 
                                                  (* Now we'll merge the two halves of the extract, writing the result back to the original section of list. *)
                                                 
                                                  set j to 1 -- Left half loop index.
                                                  set leftLen to m - l + 1 -- The length of the left half (to the middle of the extract).
                                                  set k to leftLen + 1 -- Right half loop index.
                                                  set extractLen to r - l + 1 -- The length of the extract.
                                                 
                                                  -- Get the first value from each half of the extract.
                                                  set leftVal to item j of o's extract
                                                  set rightVal to item k of o's extract
                                                  repeat with i from l to r -- 'i' indexes this section in the original list.
                                                                   if (rightVal < leftVal) then
                                                                                    -- If the current right value's less than the current left one, put it in this slot of the original list.
                                                                                    set item i of o's mainList to rightVal
                                                                                    if (k < extractLen) then
                                                                                                     -- If there are more values in the right half of the extract, get the next one …                
                                                                                                     set k to k + 1
                                                                                                     set rightVal to item k of o's extract
                                                                                    else
                                                                                                     -- … otherwise dump the remaining left values to the original list and end this recursion level.
                                                                                                     repeat with i from (i + 1) to r
                                                                                                                      set item i of o's mainList to item j of o's extract
                                                                                                                      set j to j + 1
                                                                                                     end repeat
                                                                                                     exit repeat
                                                                                    end if
                                                                   else
                                                                                    -- If the current left value's less than or equal to the current right one, put it in this original-list slot.
                                                                                    set item i of o's mainList to leftVal
                                                                                    if (j < leftLen) then
                                                                                                     -- If there are more values in the left half of the extract, get the next one …
                                                                                                     set j to j + 1
                                                                                                     set leftVal to item j of o's extract
                                                                                    else
                                                                                                     -- … otherwise end this recursion level.
                                                                                                     -- The remaining right values were already in place in the list when the extract was obtained.
                                                                                                     exit repeat
                                                                                    end if
                                                                   end if
                                                  end repeat
                                 end msort
                end script
               
                set listLen to (count theList)
                if (listLen > 1) then
                                 -- Translate negative indices
                                 if (l < 0) then set l to listLen + l + 1
                                 if (r < 0) then set r to listLen + r + 1
                                 
                                 if (r = l) then
                                                  -- No point in sorting just one item
                                 else
                                                  -- Transpose transposed indices
                                                  if (l > r) then
                                                                   set temp to l
                                                                   set l to r
                                                                   
                                                                   set r to temp
                                                  end if
                                                 
                                                  o's msort(l, r)
                                 end if
                end if
               
                return -- nothing
end mergeSort

on SortAList()
                set sortedList to {}
                set calcList to {}
                set listSize to count of listToSort
                repeat listSize times
                                 set the end of sortedList to {}
                                 set the end of calcList to {1}
                end repeat
                set i to 1
                set y to 2
                repeat
                                 set thisItem to item i of listToSort
                                 repeat with x from y to count of listToSort
                                                  set compItem to item x of listToSort
                                                 
                                                  if (thisItem) > (compItem) then
                                                                   set item i of calcList to (item i of calcList) + 1
                                                  else if (thisItem) < (compItem) then
                                                                   set item x of calcList to (item x of calcList) + 1
                                                  end if
                                 end repeat
                                 set i to i + 1
                                 set y to y + 1
                                 if y > listSize then exit repeat
                end repeat
                repeat with x from 1 to count of calcList
                                 set biggerThanCount to item x of calcList
                                 set the end of item (biggerThanCount) of sortedList to item x of listToSort
                end repeat
                set finalList to {}
                repeat with thisItem in sortedList
                                 repeat with thisValue in thisItem
                                                  set the end of finalList to thisValue as item
                                 end repeat
                end repeat
                return finalList
end SortAList





------------------------------

Message: 7
Date: Wed, 25 Aug 2010 09:44:24 +0200
From: Axel Luttgens <email@hidden>
Subject: Re: Sorting a list of records
To: asu <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=iso-8859-1

Le 25 août 2010 à 06:49:27, email@hidden a écrit :

> The merge sort seems more complicated and a lot slower. Am I missing something?
>
> set listToSort to {}
> repeat with x from 1 to 100
>                  set myData to random number from 1 to 10
>                  set the end of listToSort to myData
> end repeat
> copy listToSort to originalList
>
> set sortAListStart to current date
> set sortedLists to SortAList()
> set sortAListEnd to current date
> set sortAListElapse to sortAListEnd - sortAListStart
> set mergeStart to current date
> mergeSort(listToSort, 1, -1)
> set mergeEnd to current date
> set mergeElapse to mergeEnd - mergeStart
>
> [...]

Hello Ed,

Have you tried with longer lists?

That said, it seems that the execution speed of your SortAList() handler may be greatly enhanced by prefixing each occurrence of a property with "my" (as in: my sortedList, my calcList, my listToSort...).
Yeah, that old trick again. ;-)

Here, with that slight modification, SortAList() and mergeSort() have similar execution times for lists up to about 500 items.

Axel




------------------------------

Message: 8
Date: Wed, 25 Aug 2010 09:40:45 -0400
From: Geoff Graham <email@hidden>
Subject: Re: One more thing...
To: asu users <email@hidden>
Message-ID: <email@hidden>
Content-Type: text/plain; charset=us-ascii

If you're going to go the brute force route, you might as well go in all the way:

repeat with i from 0 to 6
                set ifstring to "ipconfig getifaddr en" & i
                try
                                 set ipAddress to do shell script ifstring
                                 return the result
                end try
end repeat

geoff


On Aug 24, 2010, at 5:36 PM, email@hidden wrote:

> Nice script.
>
>  You may try this:
>
> try
>                  set ipAddress to do shell script "ipconfig getifaddr en1"
> on error
>                  set ipAddress to do shell script "ipconfig getifaddr en0"
> end try
>



------------------------------

Message: 9
Date: Wed, 25 Aug 2010 11:00:42 -0400
From: "Mark J. Reed" <email@hidden>
Subject: Re: One more thing...
To: Geoff Graham <email@hidden>
Cc: asu users <email@hidden>
Message-ID:
                <AANLkTi=AUqgxwhVy35NfUj+Kmn7E3ROLLK=email@hidden>
Content-Type: text/plain; charset=UTF-8

See my script.  Not all interfaces are named "en". :)

On Wed, Aug 25, 2010 at 9:40 AM, Geoff Graham <email@hidden> wrote:
> If you're going to go the brute force route, you might as well go in all the way:
>
> repeat with i from 0 to 6
>        set ifstring to "ipconfig getifaddr en" & i
>        try
>                set ipAddress to do shell script ifstring
>                return the result
>        end try
> end repeat
>
> geoff
>
>
> On Aug 24, 2010, at 5:36 PM, email@hidden wrote:

>
>> Nice script.
>>
>>  You may try this:
>>
>> try
>>       set ipAddress to do shell script "ipconfig getifaddr en1"
>> on error
>>       set ipAddress to do shell script "ipconfig getifaddr en0"
>> end try
>>
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives:
http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>



--
Mark J. Reed <email@hidden>


------------------------------

_______________________________________________
AppleScript-Users mailing list
email@hidden
http://lists.apple.com/mailman/listinfo/applescript-users

End of AppleScript-Users Digest, Vol 7, Issue 435
*************************************************

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: The Apache-Apple Event Bridge 1.5 released
  • Next by Date: Setting mouse preference and space preference values via AppleScript
  • Previous by thread: The Apache-Apple Event Bridge 1.5 released
  • Next by thread: Setting mouse preference and space preference values via AppleScript
  • Index(es):
    • Date
    • Thread