0

I'm trying to create an Applescript that will change the MAC address of my router automatically. Some fields need to be even numbers but I can't figure out how to generate even numbers only. Heres what I have so far ..

set rand1 to (random number from 10 to 98) as string
set rand2 to (random number from 10 to 98) as string
set rand3 to (random number from 10 to 98) as string
set rand4 to (random number from 10 to 98) as string

tell application "Safari"
    activate
    open location "router-address/WanMAC.asp"
    tell application "System Events"
        delay 1
        keystroke "login"
        keystroke tab
        keystroke "password"
        delay 1
        keystroke return
        delay 1
        keystroke tab
        keystroke rand1
        keystroke tab
        keystroke rand2
        keystroke tab
        keystroke rand3
        keystroke tab
        keystroke rand4
        submit via javascript?
    end tell
end tell

Pretty rudimentary I know. But the basic idea is to fill in my login credentials, tab to the form fields that need to be changed, inputs a valid MAC address and then submits the form. Can anyone help? Thank you.

4 Answers 4

2

You can just multiply by 2:

(random number from 5 to 49) * 2
1
  • Ahh how simple. I feel like an idiot .. thanks :-)
    – Pieter
    Commented May 9, 2013 at 15:44
0
set rand to (random number from 0 to 99)
if rand mod 2 is not equal to 0 then
    set rand to rand - 1
end if
0

Here is another option:

set rand1 to randNum(10, 98)

on randNum(low, high)
    (random number from low to high)
    tell the result to if it mod 2 = 0 then return it
    randNum(low, high)
end randNum
0

I thought this was a handy bit of code to tidy up and expand on a bit.

on evenRandomNumber(low, high)
    repeat
        set randomNumber to (random number from low to high)
        if randomNumber mod 2 = 0 then exit repeat
    end repeat
    return randomNumber
end evenRandomNumber

on oddRandomNumber(low, high)
    repeat
        set randomNumber to (random number from low to high)
        if randomNumber mod 2 ≠ 0 then exit repeat
    end repeat
    return randomNumber
end oddRandomNumber

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .