Need an Applescript that simply renews my DHCP Lease for my current WIFI network.
thx
Need an Applescript that simply renews my DHCP Lease for my current WIFI network.
thx
Here is a short sample script you can modify
on run
local hardwareList, anItem, tid
set tid to text item delimiters
set text item delimiters to return & return
set hardwareList to do shell script "networksetup -listallhardwareports"
set hardwareList to rest of (text items of hardwareList)
repeat with anItem in hardwareList -- find the Wi-Fi hardware if it exists
set text item delimiters to return
set contents of anItem to text items of anItem
set text item delimiters to ": "
if (count (text items of item 1 of anItem)) > 1 then
if text item 2 of item 1 of anItem = "Wi-Fi" then
set anItem to text item 2 of item 2 of anItem
exit repeat
end if
end if
end repeat
if (class of anItem) = text then
if "Currently" is not in (do shell script "networksetup -getairportnetwork " & anItem) then -- wifi is connected
do shell script "ipconfig set " & anItem & " DHCP" user name "super" password "Diesel615#" with administrator privileges
end if
end if
set text item delimiters to tid
end run
or here is a slighlthly different version using different options for the ‘networksetup’ command…
on run
local hardwareList, anItem, tid
set tid to text item delimiters
set text item delimiters to return & return
set hardwareList to text items of (do shell script "networksetup -listnetworkserviceorder")
set text item delimiters to return
set item 1 of hardwareList to (text items 2 thru -1 of item 1 of hardwareList) as text
repeat with anItem in hardwareList -- find the Wi-Fi hardware if it exists
set anItem to text item 2 of anItem
set text item delimiters to {"(", ")", ": ", ", "}
set anItem to text items of anItem
if item 3 of anItem = "Wi-Fi" then
set anItem to item 5 of anItem
exit repeat
end if
set text item delimiters to return
end repeat
if (class of anItem) = text then
if "Currently" is not in (do shell script "networksetup -getairportnetwork " & anItem) then -- wifi is connected
do shell script "ipconfig set " & anItem & " DHCP" user name "super" password "Diesel615#" with administrator privileges
end if
end if
set text item delimiters to tid
end run
Oh; thank you so much. I assume I change “Wi-Fi” to the name of my Network?
No.
WI-Fi is the name for the built-in wireless adapters on the mac
It is the name of the hardware, not your configurations
The line: ‘do shell script "networksetup -getairportnetwork " & anItem’
is what gets the name of the Wireless network to which you are currently connected.
Got it. Thanks again.
Edited the appropriate parameters; but unfortunately both scripts won’t yet work. Still have to renew DHCP manually. I’m Running the latest 13.3 Ventura Beta. Perhaps the script needs to include a code insertion that “applies” the settings.
What indication are you getting to let you know it didn’t work?
Alternatives:
Set DHCP manual - set DHCP auto
do shell script "networksetup -setmanualwithdhcprouter Wi-Fi 127.0.0.1"
delay 2
do shell script "networksetup -setdhcp Wi-Fi"
do shell script "networksetup -setairportpower en0 off"
delay 2
do shell script "networksetup -setairportpower en0 on"
do shell script "networksetup -setnetworkserviceenabled Wi-Fi off"
delay 2
do shell script "networksetup -setnetworkserviceenabled Wi-Fi on"
doesn’t really give any indication; but it doesn’t fix my original issue of wifi not getting weather location running through shortcuts. Only a manual DHCP button refresh corrects the issue. Hoping for a script that actives instantly instead of having to dig down 5 layers to find that silly Renew DHCP button.
First we’re hearing of this other issue.
Can you be ultra specific on what you are trying to do and with what Apps?
When I run a weather forecast from shortcuts I’ll get a location wifi error. The only way to fix it is to dig deep into settings and click the silly Renew DHCP Lease button. Time consuming. Just trying to get a one click fix to renew DHCP; but no script has yet worked. Running 13.3 (a) Beta
Can you share the shortcut?