How can I get Hardware (Mac) Address using applescript. Please tell me how can I do it. I have searched in the dictionary but I found nothing there.
Why I need it, I have developed some tool for InDesign & Quark User. I want to add the mentioned module in my application, so that as user will run the tool it will first validate the Hardware address, and if it match then application will run otherwise it will show a piracy message.
I like this version (which I use in 10.4 only) because it’s faster than a shell call:
set MAC to primary Ethernet address of (get system info)
set B to button returned of (display dialog "Your MAC address is: " & MAC buttons {"To Clipboard as is", "No Colons -> Clip", "Done"} default button 3)
if B is "To Clipboard as is" then
set the clipboard to MAC
else if B is "No Colons -> Clip" then
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set MAC to (text items of MAC)
set AppleScript's text item delimiters to tid
set the clipboard to MAC as text
end if
set MAC to characters 8 thru -2 of (do shell script "ifconfig en0 ether | grep -i ether") as string
set B to button returned of (display dialog "Your MAC address is: " & MAC buttons {"To Clipboard as is", "No Colons -> Clip", "Done"} default button 3)
if B is "To Clipboard as is" then
set the clipboard to MAC
else if B is "No Colons -> Clip" then
set the clipboard to (words 2 thru -1 of (do shell script "ifconfig en0 ether | grep -i ether" as string)) as text
end if
On my machine, doing a shell script often has a latency of about 100 mSec - but variable. I usually time any script speed comparison with Nigel Garvey’s comparison script below. GetMilliSec is an osax. We have it on site (osaxen.com)
main()
on main()
set lotsa to 500
-- Any other preliminary values here.
-- Dummy loop to absorb a small observed
-- time handicap in the first repeat.
repeat lotsa times
end repeat
-- Test 1.
set t to GetMilliSec
repeat lotsa times
-- First test code or handler call here.
end repeat
set t1 to ((GetMilliSec) - t) / 1000
-- Test 2.
set t to GetMilliSec
repeat lotsa times
-- Second test code or handler call here.
end repeat
set t2 to ((GetMilliSec) - t) / 1000
-- More test loops here if required.
-- Timings.
return {t1, t2, t1 / t2}
end main
GetMilliSec works in both Classic and OS X and it’s author has never updated the read me, I guess. There’s no mystery though, Mark, it only does one thing: it returns the number of milliseconds since system startup, has no other functions, no arguments of any kind. It’s own latency isn’t bad.
-- usual usage
set A to GetMilliSec
set B to GetMilliSec
B - A --> 2 on my machine.
If you want to use it in an expression, enclose it in parentheses:
(GetMilliSec) - (GetMilliSec) --> small negative number
vis-a-vis latency, this is the best I can figure:
set T to 0
repeat 1000 times
(GetMilliSec) - (GetMilliSec)
set T to T + result
end repeat
T / 1000 --> ~ 0.5 on mm