Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
Thanks for sharing the video đź‘Ť

Hmmmmm....
I set up and ran the two scripts like in your video to compare and apart from you sharing ethernet (and me sharing Wifi) it looks the same. I see that with the "off" script you also have the network interface (ethernet) disabled like I have wifi disabled (instead of just turned off), so that's obviously how it should work.

With that out of the way I tried something new: opening up a Terminal window while having the Network system preference window open I first entered this:

Code:
networksetup -setnetworkserviceenabled Wi-Fi on
Screen Shot 2022-06-27 at 17.45.10.png


Then I tried the following command which resulted in this:

Code:
networksetup -setnetworkserviceenabled Wi-Fi off

Screen Shot 2022-06-27 at 17.46.16.png

and finally I repeated the "on" command. This resulted once again in "Wifi off".

So the command switches between wifi OFF and wifi DISABLED, but not wifi ON.
I would expect the "off" command to work as the "on" command does now (wifi=off) and there must be some command for turning it on. Confusing.
I'll search to see if I can find other options for "networksetup -setnetworkserviceenabled".


UPDATE: aha! I found some information here which I tested working:

Code:
networksetup -setairportpower en0 on
turns wifi ON

and

Code:
networksetup -setairportpower en0 on
turns wifi OFF.

So I'm going to try that in the scripts and see if I get it all working.


..... testing.....

The "on" script almost works with the new wifi command, but while it does enable wifi it doesn't share via wifi but looks for a network instead. Here's the updated script, and I'm wondering what the line in bold does and if it has something to do with it not quite working:

Rich (BB code):
try
    do shell script "killall 'System Preferences'"
end try
do shell script "sudo launchctl unload /System/Library/LaunchDaemons/com.apple.NetworkSharing.plist" with administrator privileges
do shell script "sudo /usr/libexec/PlistBuddy -c 'Set NAT:Enabled 1' /Library/Preferences/SystemConfiguration/com.apple.nat.plist" with administrator privileges
do shell script "sudo launchctl load /System/Library/LaunchDaemons/com.apple.NetworkSharing.plist" with administrator privileges
do shell script "networksetup -setairportpower en0 on"
do shell script "open -a /Applications/System\\ Preferences.app"
do shell script "open /System/Library/PreferencePanes/SharingPref.prefPane"


The "off" script appears to work (it switches off wifi and network sharing) -I tried it after "manually" enabling wifi sharing. But as it also has the same "NAT: Enabled" command I can't say for sure if it too needs some tweaking.
 
Last edited:

Slartibart

macrumors 68040
Aug 19, 2020
3,140
2,815
tell application "System Preferences" activate reveal (pane id "com.apple.preferences.sharing") delay 0.3 set current pane to pane "com.apple.preferences.sharing" delay 0.3 set localized_window to the localized name of the current pane set localized_app to (localized string "System Preferences") set localized_ok to {localized string "OK"} -- File sharing set localized_start to {localized string "START"} -- Internet sharing end tell delay 0.3 tell application "System Events" tell process "System Preferences" click checkbox 1 of row 7 of table 1 of scroll area 1 of group 1 of window localized_window delay 0.2 select row 8 of table 1 of scroll area 1 of group 1 of window localized_window -- change row numbers to the service you want toggled if (exists sheet 1 of window localized_window) then try click button (localized_ok as string) of sheet 1 of window localized_window on error click button (localized_start as string) of sheet 1 of window localized_window end try end if set sharing_state to the value of item 1 of static text of group 1 of window localized_window end tell tell application "System Preferences" to quit display notification sharing_state with title localized_app -- display notification exists since OS 10.9, for older systems use: -- display dialog sharing_state buttons {localized_ok} default button 1 with title localized_app giving up after 1.5 end tell

taken from an older discussion I participated in on stack exchange.
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
taken from an older discussion I participated in on stack exchange.

Cool! A single script that toggles on/off makes things even simpler.
But I can't get it to work here on 10.13 High Sierra (it looks like the script is the last one in the discussion thread, modified for OSX 10.14 Mojave).
After allowing it in the OSX security preferences it does run, but ticks on/off "Remote Apple events" (instead of "Internet sharing" and doesn't toggle wifi on and off.
I bet the first problem is the checkbox number which doesn't match "Internet sharing", and although wifi doesn't have a checkbox it might be the same thing there -I'll look into it.

UPDATE: I believe I have a working version of the script :)
I'll do some extensive testing and check back here when done
 
Last edited:

Slartibart

macrumors 68040
Aug 19, 2020
3,140
2,815
gui scripting… you have to check what Apple changed between MacOS releases to get the right pane… :cool:
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
OK, got it working after some minor tweaking! đź‘Ť
I used the version for OSX 10.11 El Capitan by Bernhard Wagner, then I added the OSX notofication related parts from your 10.14 version tweaked a bit (in bold below). I don't know if the syntax is 100% correct, but it appears to work as intended. Here it is:

Rich (BB code):
-- This script toggles between on/off for sharing Wifi-Internet from a Mac
-- slightly modified (Notifications added) from the original script which was found here:
-- https://apple.stackexchange.com/a/226679


tell application "System Preferences"
    activate
    reveal (pane id "com.apple.preferences.sharing")
    set localized_window to the localized name of the current pane
end tell

tell application "System Events" to tell process "System Preferences"
    delay 1
    repeat with r in rows of table 1 of scroll area 1 of group 1 of window localized_window
        if (value of static text of r as text) starts with "Internet" then
            set sharingBool to value of checkbox of r as boolean
            select r
            if sharingBool is true then
                do shell script "/usr/sbin/networksetup -setairportpower en1 off"
            else
                do shell script "/usr/sbin/networksetup -setairportpower en1 on"
            end if
            click checkbox of r
        end if
    end repeat
    delay 1
  
    if (exists sheet 1 of window localized_window) then
        click button "Start" of sheet 1 of window localized_window
    end if
  
    -- display status in OSX notifications   
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    display notification sharing_state with title "Wifi Internet-sharing"
  
  
end tell

ignoring application responses
    tell application "System Preferences" to quit
end ignoring

The OSX notification that I took from the OSX 10.14 script originally looked like this (with "localized_app" changed to "localized_window"):
Code:
    -- display status in OSX notifications 
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    display notification sharing_state with title localized_window
Screen Shot 2022-06-27 at 20.37.19.png


But I changed it slightly and now it looks like this, with a more accurate title:
Code:
    -- display status in OSX notifications 
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    display notification sharing_state with title "Wifi Internet-sharing"
Screen Shot 2022-06-27 at 22.40.21.png


To make it quicker to read at a glance, is there a way that I can change this to something shorter like "Status: ON" or simply "ON", possibly in bold text?
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
But that would just display the sharing status as "ON" all the time.
I meant to have a notification something like this when it's on:

Wifi Internet sharing
Status: ON


and when it's toggled again, to turn it off:

Wifi Internet sharing
Status: OFF


(or even without the "Status:" part so it just shows "ON" and "OFF" making it even simpler and easier to read at a glance).
But I'm really just nitpicking here as the script works great I'm guessing it would involve more than just replacing some of the coding but might need some new code. But if someone knows of a simple solution.... ;)
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
OK, I see.
I typed in the text from your screenshot to try out but am a little unsure about how to incorporate it into the rest of the script.
With my limited coding abilities I'm guessing from the code that this "NSString" might be the wifi status string, but may be way off here :oops:
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
Another thing.....
I've used the script for several days now and all's working well. But I'm wondering if it would be possible to have the script do its thing "in the background" (i.e. without opening the system preferences and ticking off the choices etc.)?

It's OK for me as I know what's supposed to happen, but for someone else they might get confused and start clicking on a window to close it or something, thereby messing up the process.
If this is possible to do, maybe an alert should pop up (and stay for a couple of seconds before automatically closing) saying that Wifi sharing is about to be enabled (or disabled) in a few seconds, and then the Notification Center will finally confirm that it's been enabled or disabled.
 

bogdanw

macrumors 603
Mar 10, 2009
6,099
3,011
I’ve tested the script from post 17 on a M1 MacBook with Monterey and it’s working perfectly.
On High Sierra, networksetup -setnetworkserviceenabled Wi-Fi might need sudo, according to an old post https://apple.stackexchange.com/que...d-for-disconnecting-wifi-from-current-network
Try

Code:
try
    do shell script "killall 'System Preferences'"
end try
do shell script "sudo launchctl unload /System/Library/LaunchDaemons/com.apple.NetworkSharing.plist" with administrator privileges
do shell script "sudo /usr/libexec/PlistBuddy -c 'Set NAT:Enabled 1' /Library/Preferences/SystemConfiguration/com.apple.nat.plist" with administrator privileges
do shell script "sudo launchctl load /System/Library/LaunchDaemons/com.apple.NetworkSharing.plist" with administrator privileges
do shell script "sudo networksetup -setnetworkserviceenabled Wi-Fi on" with administrator privileges
do shell script "open -a /Applications/System\\ Preferences.app"
do shell script "open /System/Library/PreferencePanes/SharingPref.prefPane"


Code:
try
    do shell script "killall 'System Preferences'"
end try
do shell script "sudo networksetup -setnetworkserviceenabled Wi-Fi off" with administrator privileges
do shell script "sudo launchctl unload /System/Library/LaunchDaemons/com.apple.NetworkSharing.plist" with administrator privileges
do shell script "sudo /usr/libexec/PlistBuddy -c 'Set NAT:Enabled 0' /Library/Preferences/SystemConfiguration/com.apple.nat.plist" with administrator privileges
do shell script "sudo launchctl load /System/Library/LaunchDaemons/com.apple.NetworkSharing.plist" with administrator privileges
do shell script "open -a /Applications/System\\ Preferences.app"
do shell script "open /System/Library/PreferencePanes/SharingPref.prefPane"
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
So it's all done by removing "activate" at the start of the script?
I removed it (disabled as a comment) from the script I'm using and so far it appears to work perfectly as before, but without the system preference windows from popping up! :)
Is there a way to display an alert window (not a notification) in the middle of the screen which automatically closes after a couple of seconds, but without needing any user interaction? I've found a lot of examples of Applescript dialogs, but they all have "OK" and "Cancel" button.

The updated script here, but now "invisible" (system prefs won't pop up as before):
Code:
-- This script toggles between on/off for sharing Wifi-Internet from a Mac
-- slightly modified (Notifications added) from the original script which was found here:
-- https://apple.stackexchange.com/a/226679
-- version 1.1 (system preference windows no longer appear)

tell application "System Preferences"
    --    activate
    reveal (pane id "com.apple.preferences.sharing")
    set localized_window to the localized name of the current pane
end tell

tell application "System Events" to tell process "System Preferences"
    delay 0.5
    repeat with r in rows of table 1 of scroll area 1 of group 1 of window localized_window
        if (value of static text of r as text) starts with "Internet" then
            set sharingBool to value of checkbox of r as boolean
            select r
            if sharingBool is true then
                do shell script "/usr/sbin/networksetup -setairportpower en1 off"
            else
                do shell script "/usr/sbin/networksetup -setairportpower en1 on"
            end if
            click checkbox of r
        end if
    end repeat
    delay 1
    
    if (exists sheet 1 of window localized_window) then
        click button "Start" of sheet 1 of window localized_window
    end if
    
    -- display status in OSX notifications   
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    display notification sharing_state with title "Wifi sharing"
    
end tell

ignoring application responses
    tell application "System Preferences" to quit
end ignoring
 

bogdanw

macrumors 603
Mar 10, 2009
6,099
3,011
  • Like
Reactions: chown33

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
It seems there's no way in Applescript to create an alert or dialog window without buttons to press :(

So I considered using the Notifications instead by adding a notification at the very start of the script (so the user can see something is happening):
Code:
display notification with title "AppleScript running" subtitle "PLEASE WAIT...."

That worked of course, but before that window closed the above text got replaced with the end resulting notification text as from this part of the script:
Code:
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    display notification sharing_state with title "Wifi sharing"

The whole idea with the alerting is to_
1) alert the user that something has indeed started up (despite not seeing anything happening on the screen)
and
2) tell the user what has happened (wifi sharing status on or off)

From a user point of view I would want a new window of some sort to pop up to alert that new information is presented and should be read, so one solution was to change the delay further down the script from 0.5 to 2.1 (anything shorter just replaced the text in the same window).
This would allow the first notification to close, followed by a new one opening, but of course taking longer for the script to complete. Here's the entire script with these changes:

Code:
-- This script toggles between on/off for sharing Wifi-Internet from a Mac
-- slightly modified (Notifications added) from the original script which was found here:
-- https://apple.stackexchange.com/a/226679
-- version 1.2 (system preference windows no longer appear. Extra notification added at start)

display notification with title "AppleScript running" subtitle "PLEASE WAIT...."


tell application "System Preferences"
    --    activate
    reveal (pane id "com.apple.preferences.sharing")
    set localized_window to the localized name of the current pane
end tell

tell application "System Events" to tell process "System Preferences"
    delay 2.1
    repeat with r in rows of table 1 of scroll area 1 of group 1 of window localized_window
        if (value of static text of r as text) starts with "Internet" then
            set sharingBool to value of checkbox of r as boolean
            select r
            if sharingBool is true then
                do shell script "/usr/sbin/networksetup -setairportpower en1 off"
            else
                do shell script "/usr/sbin/networksetup -setairportpower en1 on"
            end if
            click checkbox of r
        end if
    end repeat
    delay 1
   
    if (exists sheet 1 of window localized_window) then
        click button "Start" of sheet 1 of window localized_window
    end if
   
    -- display status in OSX notifications  
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    display notification sharing_state with title "Wifi sharing"
   
end tell

ignoring application responses
    tell application "System Preferences" to quit
end ignoring

It would be great if I could shorten the duration of the first notification but there doesn't appear to be a way to do that according to what I've read. If someone knows of a solution though, please share!

A minor detail which would make things clearer for the user would be to have the "on" or "off" status in UPPERCASE.
According to this documentation it's a simple matter to change text to uppercase:
Code:
changeCaseOfText("here is a line of text", "upper")

But if I'm not mistaken I need to change the result of the sharing_state string to uppercase, but this didn't work:
Code:
display notification changeCaseOfText (sharing_state) with title "Wifi sharing"

Is the syntax I've used above wrong, or does this only work for text itself (not the results of a string) and I need to add some extra lines of code such as in this thread posting:
Code:
set newString to makeUpper2("yOurSTringHeRe")

on makeUpper2(inString)

  return (do shell script "awk '{ print toupper($0) }' <<< \"" & inString & "\"")

end makeUpper2
 

kryten2

macrumors 65816
Mar 17, 2012
1,115
99
Belgium
It seems there's no way in Applescript to create an alert or dialog window without buttons to press :(
Screenshot 2022-07-03.png

Post something where you've tried to implement what you found as a whole script. Those one-liners are useless as there are pieces missing. What is the result of that last piece of code when you run it and replace "yOurSTringHeRe" with "Internet Sharing: On". Is the result as you expected?

Info: cocoaDialog
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
Sorry about that. I'll try to post the results as well.
I haven't actually tried out the last piece of code yet as I didn't know if it was even applicable for this situation or not (I'm not very familiar with coding so it's not obvious to me).
Does it look like this could to the trick (change the results of the "sharing_state" string to all UPPERCASE)?

That screenshot of the window without any buttons is exactly what I'm after! So does that mean everybody who uses the script is dependant on having CocoaDialog installed, or does only the person who creates the script (me) need to install it?
(the link with the documentation referred to from the readme.md file doesn't work, neither is it obvious how to install/use it -I didn't find any documentation with the download either).

I have a strange problem.....
While the version 1.2 script (posted above, in posting #41) works fine after being saved as an application it no longer displays any notifications when running. When ran from the Script editor it worked as intended. What might the cause for this be? I've already added it to the Accessibility part of the Security & Privacy system preferences so it can't be that.
It seems that putting back activate (one of the first lines of the script) enables the notifications again.
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,115
99
Belgium
I haven't actually tried out the last piece of code yet as I didn't know if it was even applicable for this situation or not (I'm not very familiar with coding so it's not obvious to me).
Please do try.
Does it look like this could to the trick (change the results of the "sharing_state" string to all UPPERCASE)?
Seems like it. Try stuff.
That screenshot of the window without any buttons is exactly what I'm after! So does that mean everybody who uses the script is dependant on having CocoaDialog installed, or does only the person who creates the script (me) need to install it?
(the link with the documentation referred to from the readme.md file doesn't work).
If you install it in Applications then everybody can use it on the same computer. Unfortunately this is old soft, documentation is missing, broken links etc. The link provides some examples and there's other stuff out there.
I have a strange problem.....
Your favorite search engine might offer some clues.
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
Thanks for your suggestions!
Yes, I'll give it a go. More below, but good news -I found a solution to the lacking OSX Notifications when run as an application. According to this thread, OSX Notifications won't show when the application sending the notifications is in the foreground, so I followed the suggestion and put the OSX Finder in the foreground (making my script-application go to the background) by adding the following at the start of the script, and presto! it worked :)
Code:
tell application "Finder" to activate

If you install it in Applications then everybody can use it on the same computer. Unfortunately this is old soft, documentation is missing, broken links etc. The link provides some examples and there's other stuff out there.

Oh, I see.
That'll increase the risk of people not getting the script to work properly because they forget to install CocoaDialog or don't understand how IMHO.
It's cool that custom icons for OSX Notifications can be added to an Applescript application to be used by the same script so that everything is self-contained. Unless CocoaDialog (or some similar script enhancement) can be used the same way I think it might be better just to stick with the two Notifications with a delay in between.

Concerning changing the "on" and "off" result of the sharing_state string to UPPERCASE, I've looked at the previously mentioned code and think it's a matter of using it with that case-conversion code, then creating a new string (sharing_state_UPPERCASE) which is passed on to the OSX Notifications. Does that sound right?
Code:
    -- display status in OSX Notifications 
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    
    -- convert to UPPERCASE   
set newString to sharing_state_UPPERCASE("sharing_state")
on makeUpper2(inString)
return (do shell script "awk '{ print toupper($0) }' <<< \"" & inString & "\"")
end sharing_state_UPPERCASE
    
    -- UPPERCASE result displayed in OSX Notifications
    display notification sharing_state_UPPERCASE with title "Wifi sharing"

But this results in an error regarding the syntax:
Screen Shot 2022-07-04 at 12.24.09.png


It seems I need to use a different syntax in this context, while in the example from the other thread it works like I used it. I'm not sure what to change here.



Here's the entire script with it in context:
Code:
-- This script toggles between on/off for sharing Wifi-Internet from a Mac
-- slightly modified (Notifications added) from the original script which was found here:
-- https://apple.stackexchange.com/a/226679
-- further improvements discussed here: https://forums.macrumors.com/threads/applescript-or-other-solution-wifi-sharing-on-off.2344505/
-- version 1.4     changelog:
-- System Preference window now hidden
-- Additional OSX Notification at start (alerting that the script is running)
-- Finder set to foreground (otherwise OSX Notifications won't display)
-- On/off status displayed in OSX Notifications in UPPERCASE for increased clarity



tell application "Finder" to activate

display notification with title "AppleScript running" subtitle "PLEASE WAIT...."

tell application "System Preferences"
    -- activate
    reveal (pane id "com.apple.preferences.sharing")
    set localized_window to the localized name of the current pane
end tell


tell application "System Events" to tell process "System Preferences"
    delay 3
    repeat with r in rows of table 1 of scroll area 1 of group 1 of window localized_window
        if (value of static text of r as text) starts with "Internet" then
            set sharingBool to value of checkbox of r as boolean
            select r
            if sharingBool is true then
                do shell script "/usr/sbin/networksetup -setairportpower en1 off"
            else
                do shell script "/usr/sbin/networksetup -setairportpower en1 on"
            end if
            click checkbox of r
        end if
    end repeat
    delay 1
    
    if (exists sheet 1 of window localized_window) then
        click button "Start" of sheet 1 of window localized_window
    end if
    
    -- display status in OSX Notifications 
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
    
    -- convert to UPPERCASE   
set newString to sharing_state_UPPERCASE("sharing_state")
on makeUpper2(inString)
return (do shell script "awk '{ print toupper($0) }' <<< \"" & inString & "\"")
end sharing_state_UPPERCASE
    
    -- UPPERCASE result displayed in OSX Notifications
    display notification sharing_state_UPPERCASE with title "Wifi sharing"
    
    
end tell

ignoring application responses
    tell application "System Preferences" to quit
end ignoring
 

kryten2

macrumors 65816
Mar 17, 2012
1,115
99
Belgium
Code:
   -- display status in OSX Notifications
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window   
    
end tell

    -- UPPERCASE result displayed in OSX Notifications
    display notification makeUpper2(sharing_state) with title "Wifi sharing"

    -- convert to UPPERCASE

on makeUpper2(inString)

  return (do shell script "awk '{ print toupper($0) }' <<< \"" & inString & "\"")

end makeUpper2

ignoring application responses
    tell application "System Preferences" to quit
end ignoring
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,023
164
Norway
Awesome! Much appreciated :)
I see both my syntax and order of things was wrong (I assumed the actual displaying of the notification came after having done the case-conversion).
Nevertheless the script works great now! And I'm sharing it below along with a bunch of different application icons to each ones liking.
First, here's the final script itself with all the changes:
Code:
-- This script toggles between on/off for sharing Wifi-Internet from a Mac
-- slightly modified (Notifications added) from the original script which was found here: https://apple.stackexchange.com/a/226679
-- further improvements discussed here: https://forums.macrumors.com/threads/applescript-or-other-solution-wifi-sharing-on-off.2344505/
-- version 1.4     changelog:
-- System Preference window now hidden
-- Additional OSX Notification at start (alerting that the script is running)
-- Finder set to foreground (otherwise OSX Notifications won't display)
-- On/off status displayed in OSX Notifications in UPPERCASE for increased clarity



tell application "Finder" to activate

display notification with title "AppleScript running..." subtitle "PLEASE WAIT!"

tell application "System Preferences"
    -- activate
    reveal (pane id "com.apple.preferences.sharing")
    set localized_window to the localized name of the current pane
end tell


tell application "System Events" to tell process "System Preferences"
    delay 3
    repeat with r in rows of table 1 of scroll area 1 of group 1 of window localized_window
        if (value of static text of r as text) starts with "Internet" then
            set sharingBool to value of checkbox of r as boolean
            select r
            if sharingBool is true then
                do shell script "/usr/sbin/networksetup -setairportpower en1 off"
            else
                do shell script "/usr/sbin/networksetup -setairportpower en1 on"
            end if
            click checkbox of r
        end if
    end repeat
    delay 1
 
    if (exists sheet 1 of window localized_window) then
        click button "Start" of sheet 1 of window localized_window
    end if
 
    -- display status in OSX Notifications
    set sharing_state to the value of item 1 of static text of group 1 of window localized_window
 
 
end tell


-- OSX notification of network status (on/off)
display notification sharing_state_UPPERCASE(sharing_state) with title "Status:"


-- Convert to UPPERCASE text
on sharing_state_UPPERCASE(inString)
    return (do shell script "awk '{ print toupper($0) }' <<< \"" & inString & "\"")
end sharing_state_UPPERCASE


ignoring application responses
    tell application "System Preferences" to quit
end ignoring



.... and to anyone who's just joined in, skipped the previous discussions, but interested in installing and using the actual script:

What is this?
If you find yourself sharing WiFi-Internet from your Mac regularly, but find it tiresome to go through all the mouse-clicking, this Script-Application will do it all with one click from the OSX dock. If you have the WiFi status icon enabled in the menu-bar you'll see if it's sharing or not at any time (go to System Preferences - Network - WiFi).
The final script has been tested in MacOS 10.13.6 (High Sierra) while the original script was written and tested in MacOS 10.11.3 (El Capitan).
I take no credit in developing the script but have just made some improvements (see the changelog at the beginning of the script) and even those were mostly done with lots of help from others joining in here as well as bits and pieces of information I've found from other online sources.
I do take credit for spending time testing it all though ;)

How to use?
Just click on the app icon in the OSX dock and it'll switch on or off the current Wifi-sharing status (it's a "toggle" switch meaning it switches off when on and on when off).

How to install?
1) Download and unzip (double-click on your Mac) the attached ZIP file
2) Place the application from inside the unzipped folder anywhere you like (i.e. the /Applications/ folder or a script folder if you like to keep this sort of stuff there
3) Drag the application (from where you just placed it) and drop it into the OSX dock
Screen Shot 2022-07-04 at 16.41.26.png


4) Click on the app in the dock
5) When security-alerted (this will only happen the first time you run the script application), click on the "Open System Preferences":
Screen Shot 2022-07-04 at 16.17.37.png

6) When the Security & Privacy system preferences open, first click on the lock (bottom left corner) and enter your password, then (when unlocked) enable the script application to control your computer. Finally close the System preferences.
Screen Shot 2022-07-04 at 16.18.09.png

7) click on the application icon in the dock once again. Now it'll run properly and won't ask for your password again. Try it a few times to see that it switches on an off Wifi-sharing.
8) If you don't like the icon colour there are several others to choose from in the supplied icons folder
 

Attachments

  • WiFi-sharing 1.4 On & Off Application.zip
    155.1 KB · Views: 150
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
6,099
3,011
Has anyone found the script (downloadable from the previous posting) useful?
It is an admirable work, with ingenious solutions. But because it uses clicks in System Preferences, it might only work properly on macOS 10.13.6.
On Monterey for example, it randomly returns “System Preferences got an error: Can’t get current pane.” and other errors.
More, on laptops without an Ethernet port, Wi-Fi is en0, not en1.
Fortunately, networksetup gets past that and returns: "en1 is not a Wi-Fi interface. Turning off the only airport interface found: en0"
In the end, it works as you want it and it provides a good template for anybody with a similar problem. đź‘Ť
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.