Any Way to Connect to a Personal Hotspot?

I like to create a macro that connects my mac to a personal hotspot. Is there any way to do this?

1 Like

Hi @Bobby_joe! Welcome to the forum.

Would be glad to help, but I'm going to need to know a little more about what steps you need to take to make this happen when you are doing it manually.

To borrow from @JMichaelTX , here are some tips about getting help for Keyboard Maestro (we're always glad to help, this just makes it a little easier)

1 Like

One thing I want to say first is that KM has a built-in action for changing your network location. In order for this to work you have to learn how to create system locations in the macOS Network section of the Preferences window. (This is because it doesn't work by picking a Network Connection name, but by a level of indirection using the names in your Preferences Location list. That's something you have to set up manually.)

BUT in my testing that doesn't work because that action doesn't let you choose from your iPhone Hotspot. I'm not sure why that's the case. That's disappointing, but the alternative method is for you to create a KM macro to click on the wifi icon on the top of your Mac's screen then have the macro click on your iPhone's name when it appears (it usually takes a half second for it to appear.) I could try to write that for you but it wouldn't work for you because my macro would contain screen captures of my Wifi icon and my iPhone's name. Naturally your names and screen resolutions may differ so my macro wouldn't work for you. You would have to take your own screenshots.

SIDENOTE: Now that KM includes its own OCR facility, it might be possible for someone to create a macro to actually read the network names from the wifi pull down menu and let you use a KM macro to click on one of the names that shows up.

1 Like

In general, you could (and can) already do this via UI scripting (not tested in this particular case). UI scripting (AppleScript) is much more reliable (and less resource-expensive) than scanning found images.


See here, for example.

1 Like

In theory, this will set your network config:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
  tell network preferences
    set current location to location "HotSpot"
  end tell
end tell

Assuming you have established a Location named “HotSpot” in Network Preferences.

I said “in theory”, because currently I’m unable to create a Location with my iPhone as hotspot. This might be a bug in 10.14.6 or in the iPhone OS or with my setup, I don’t know.

I will investigate. But you got the idea.

Very nice. I'm still really a novice with KM because I rarely even think about using AppleScript.

Don’t say “nice”, because currently it doesn’t work :wink: (at least with my setup; I’m working on it)

You should. Because it “integrates” so well with KM. (Some of the KM actions are also just AppleScripts or AppleScript-Obj-C scripts). And it can give you many solutions to things where otherwise you would fall back to Select Menu Item actions or even Find Image actions.

I can’t stress it enough: Find Image (with or without OCR on those images) is a matter of last resort. If you use them as your “default” solution you are missing out on many things, and you are wasting resources. (Yes, I haven’t forgotten our conversation about your KM memory leaks :wink: )


OK, I couldn’t make my AppleScript work, and there seem to be more issues than I thought with accessing the Network Preferences via AppleScript, maybe since Mojave, not sure.

However, with this simple command line (put it into a Shell Script action) I can set my WiFi to my iPhone hot spot (assuming the iPhone is not sleeping):

networksetup -setairportnetwork en1 <network name> <password>

You may have to change en1 to en0, but probably not.

Very nice. So may I assume that to return it to Wifi we just need to use the KM action to change the network location to "Automatic"? ("Automatic" for most people will be the only name that they have installed.)

Not sure. Have you tried it? For me, changing the Location does not change the current network. (But this might be because something is fishy here, on my side…)

All the time I was speaking about a hot spot via WiFi, so it should not be about “returning to WiFi”, rather about how to change the network (with all networks being Wifi).

If you understood with “hot spot” a Blue Tooth interface (or whatever), I don’t know if the command line still works. Probably Yes, but test it. At least the interface name (“en1”) has to be changed then to the appropriate one.

Yes, I misspoke. I meant too say "regular wifi" not "wifi". Because there is something different about hotspot wifi and regular wifi. As you can see from the wifi icon, hotspot wifi links appear in a different list than regular wifi links. In fact you can't even see a wifi hotspot from the list of wifi networks in the Preferences panel. So something makes hotspots very very different from regular wifi networks. And it means you probably cannot use the KM Set Network action to change to a hotspot. Why is that? There is obviously a major functional difference between regular wifi and hotspot wifi, as far as macOS is concerned.

I do see my hot spots in the Preferences panel (as you said, you can tell it by the icon):


“Liza” is my iPhone. (And I love her, by the way.)

1 Like

Pardon if this message is a repeat, but my first attempt to post didn't register.

Are you running some beta version of macOS? I don't get hotspots showing up there. The only place they show up is when I click on the Wifi icon at the top of my screen. And even then they appear under a special menu called Personal Hotspots.

No. Regular release macOS 10.14.6.

This is true, also here.

In that case, shouldn't you be able to use the KM action "Set Network Location" to switch between hotspot and non-hotspot wifi? There shouldn't be any need to revert to AppleScript or command shells if you can see and set hotspots in your preferences.

As said, changing the Location doesn’t change the WiFi network here. No matter if done via AppleScript or KM action. (Tried both.) It does change the network interface, obviously, if I have different interfaces activated in the respective Location.

Currently not sure if I’m doing something wrong, it is bugged, or it was always like that…

I'll try to research this. It's hard for me to test since I can't see hotspots in my network list.

Have to go to sleep now…

You are sure that your hot-spot provider (eG iPhone) wasn’t sleeping?