Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Script to create an ad-hoc network to sync iPhone iOS devices
Due to the lack of an equivalent to Palm's sync conduits, many iPhone applications are syncing to your computer over a local wireless network. When I tote my laptop around with me, I often don't have a network available to sync with, or I don't trust the networks that are available. Here's an AppleScript I use to set up my laptop to talk with my phone when I'm not at home. It creates an ad-hoc network with 128-bit WEP encryption.

Optionally you can make a network location (System Preferences > Network) with the same name as the network you're creating. In addition to allowing me to configure my other network connections, this lets me easily revert to my normal networks by selecting my default location when I'm done. The iPhone will remember the password after the first time you join the network, although you may have to select it if there are multiple networks available.

If you get an error message that the network already exists, check to make sure your phone isn't keeping that ad-hoc network alive. Just selecting another network should do it.


-- This script creates an ad-hoc network with a password and changes your
-- network location.
--
-- I just added network passwords and network locations to a script which
-- comes from StefanK:
--    http://bbs.macscripter.net/viewtopic.php?pid=99243

-- Set NetworkName to be the name of the wireless network you wish
-- to create.  This will also attempt to set the network location
-- to that name as well.
-- Set NetworkPassword to be your wireless network password.  It MUST BE
-- 13 characters long (or 26 hex digits).

property NetworkName : "MyAdHocNetwork"
property NetworkPassword : "thirteenchars"


property CreateMenuName : "Create Network…"

try
	do shell script "/usr/sbin/scselect " & NetworkName
	delay 2
end try

tell application "System Events"
	tell process "SystemUIServer"
		tell menu bar 1
			set menu_extras to value of attribute "AXDescription" of menu bar items
			repeat with the_menu from 1 to the count of menu_extras
				if item the_menu of menu_extras is "Airport Menu Extra" then exit repeat
			end repeat
			tell menu bar item the_menu
				perform action "AXPress"
				delay 0.2
				perform action "AXPress" of menu item CreateMenuName of menu 1
			end tell
		end tell
		repeat until exists window 1
			delay 0.5
		end repeat
		tell window 1
			keystroke NetworkName
			click checkbox 1
			keystroke NetworkPassword
			keystroke tab
			keystroke NetworkPassword
			click pop up button 2
			click menu item 2 of menu 1 of pop up button 2
			delay 0.5
			
			click button 1
		end tell
	end tell
end tell
    •    
  • Currently 2.71 / 5
  You rated: 4 / 5 (7 votes cast)
 
[35,442 views]  

Script to create an ad-hoc network to sync iPhone | 13 comments | Create New Account
Click here to return to the 'Script to create an ad-hoc network to sync iPhone' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Script to create an ad-hoc network to sync iPhone
Authored by: Supp0rtLinux on Aug 21, '08 08:31:32AM
Due to the lack of an equivalent to Palm's sync conduits, many iPhone applications are syncing to your computer over a local wireless network
Um, feel free to call me stupid or perhaps just uninformed, but I'm a tad confused here. The iPhone won't sync to a Mac [or a PC] wirelessly (this is something we've been asking for, over BT preferably, or over wifi as an option). It syncs over the cable only (unless you're using MobileMe for contacts, calendar, etc, but everything else (music, photos, etc.) still go over the cable. So the script looks great for setting up a quick ad-hoc network. But what does this have to do with Palm's sync conduits and "iPhone applications syncing to your computer"??? The only application of this that I can see is to share your Mac's wired connection over Airport for your iPhone to get a WiFi connection...

[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: BlackjackJoe on Aug 21, '08 08:55:28AM

No name calling, but there are a few 3rd party applications that sync over a WiFi connection between the iPhone and a Mac, two that come to mind are 1Password and VoiceNotes. Although I think in the case of 1Password, it uses its own encryption anyway.



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: Supp0rtLinux on Aug 21, '08 12:37:32PM

Okay, that part makes sense. I have SplashID and it requires a wireless network to sync as well. I guess the author could have phrased things just slightly better. :)



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: luigi193 on Aug 21, '08 01:21:56PM

Yeah I'm sorta confuzzled...
You can't sync of wifi... even though people realllly wish you could!



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: channui on Aug 22, '08 11:01:26AM

One more thing. In order for this to work you need to enable access for assistive devices in System Preferences->Universal Access.



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: krader on Aug 22, '08 11:32:11AM

To answer the previous to repliers: The purpose of this is to allow iPhone applications such as OmniFocus and Things (both "Getting Things Done" applications) and SplashID to sync with their desktop counterpart. They don't sync using the iTunes wired sync mechanism. They do so using the Bonjour protocol to discover the desktop app. But that requires that the laptop and iPhone be on the same wireless network. Something you can't always arrange. For example, at my company the laptop is on a secure corporate wireless network while my iPhone can only join the public guest network. This means the apps on my iPhone can't see their desktop counterparts on my Macbook.

Being a long time UNIX user/programmer/administrator I tend to prefer shell scripts. So what I did was use the System Preferences Network panel to define an ad hoc network named "Ad Hoc" secured by a password and with 128 bit WEP encryption (to keep it simple use the same key for both).
I then wrote put two shell scripts in ~/bin named "work" and "adhoc". The adhoc script contains

#!/bin/ksh
sudo ifconfig en0 down
sudo scselect "Ad Hoc"
sudo ifconfig en1 up

Make it executable with "chmod 700 bin/adhoc" and now I can quickly switch to a private ad hoc network for syncing with my iPhone by just typing "adhoc" in a terminal window (I normally have one open anyway).
The "work" script contents should be obvious although in my case it also copies the dynamic hostname assigned to my Macbook to my Linux workstation using

hostname | ssh $workstation 'cat > .mac_hostname"

This allows me to easily connect back to my Macbook using VNC or SSH from my primary workstation.



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: Swift on Aug 25, '08 09:36:19AM

I don't know about syncing wirelessly, but this script finally allowed me to share internet with my home (wired) mac. I'm not even sure what it does differently from what I was trying to do manually, except maybe just the bare minimum. Just my luck, at work I get five bars of 3G. All around town, the same. When I go home, I get Edge, two bars. The phone calls are fine in certain rooms, but the Internet sucked. Now I get speedy Internet access. Thanks!

---
------------------------
Screenplays for Royalty
since 1749



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: mvmaastricht on Jan 13, '09 01:45:37PM
There is also a nice, little and free application that does the same and that you can put in the Dock. It let you predefine a network name and password.
It's called iPhoneModem http://www.iphonemodem.com and the application is actually part of an iPhone solution to turn your iPhone in a modem and router (only for jailbreaked iPhones). The iPhone application is $10,- but the Mac OS X "Helper App", that's part of it, is free.

[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: channui on Sep 15, '09 09:53:34AM
Here's the script updated for 10.6

-- This script creates an ad-hoc network with a password and changes your
-- network location.
--
-- I just added network passwords and network locations to a script which
-- comes from StefanK:
--    http://bbs.macscripter.net/viewtopic.php?pid=99243

-- Set NetworkName to be the name of the wireless network you wish
-- to create.  This will also attempt to set the network location
-- to that name as well.
-- Set NetworkPassword to be your wireless network password.  It MUST BE
-- 13 characters long (or 26 hex digits).

property NetworkName : "MyAdHocNetwork"
property NetworkPassword : "thirteenchars"

property CreateMenuName : "Create Network…"

try
	do shell script "/usr/sbin/scselect " & NetworkName
	delay 2
end try

tell application "System Events"
	tell process "SystemUIServer"
		tell menu bar 1
			set menu_extras to value of attribute "AXDescription" of menu bar items
			repeat with the_menu from 1 to the count of menu_extras
				if item the_menu of menu_extras is "Airport Menu Extra" then exit repeat
			end repeat
			tell menu bar item the_menu
				perform action "AXPress"
				delay 0.2
				perform action "AXPress" of menu item CreateMenuName of menu 1
			end tell
		end tell
		repeat until exists window 1
			delay 0.5
		end repeat
		tell window 1
			keystroke NetworkName
			click checkbox 1
			keystroke tab
			keystroke tab
			keystroke tab
			keystroke NetworkPassword
			keystroke tab
			keystroke NetworkPassword
			click pop up button 2
			click menu item 2 of menu 1 of pop up button 2
			delay 0.5
			click button 1
		end tell
	end tell
end tell



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: hasole on Oct 11, '09 04:05:33PM

Great hint, I was getting tired of having to create the network, entering the password and selecting 128bit every time.



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: KBoda on Oct 14, '09 03:40:56AM

Had to modify it, somehow:

keystroke tab
keystroke tab

was not required in my configuration.
Thanks for the script anyways.
Suggested feature: check whether Airport is on and turn it on if not ;)



[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: channui on Jan 29, '10 11:56:09AM
I have "Full Keyboard Access" turned on in System Preferences->Keyboard->Keyboard Shortcuts. That changes how many keystrokes are needed. Here's a version that shouldn't require that, and turns on the airport to boot.

-- This script creates an ad-hoc network with a password and changes your
-- network location.
--
-- This script mostly comes from StefanK:
--    http://bbs.macscripter.net/viewtopic.php?pid=99243

-- I just added network locations, passwords, bringup script, turning on the airport
-- and moved to directly addressing elements instead of using keystrokes.

-- Set NetworkName to be the name of the wireless network you wish
-- to create.  This will also attempt to set the network location
-- to that name as well.
-- Set NetworkPassword to be your wireless network password.  It MUST BE
-- 13 characters long (or 26 hex digits).
-- If Desired, Set BringupScript to be the name of a script to invoke
-- in a terminal after the network is created.

property NetworkName : "MyAdHocNetwork"
property NetworkPassword : "thirteenchars"
property BringupScript : ""

try
	do shell script "/usr/sbin/scselect " & NetworkName
end try

tell application "System Events"
	tell process "SystemUIServer"
		tell menu bar 1
			-- Find Airport Menu
			set menu_extras to value of attribute "AXDescription" of menu bar items
			repeat with the_menu from 1 to the count of menu_extras
				if item the_menu of menu_extras is "Airport Menu Extra" then exit repeat
			end repeat
			
			-- Turn on airport and start create network
			tell menu bar item the_menu
				perform action "AXPress"
				-- If Airport is off, turn it on
				if title of menu item 2 of menu 1 is "Turn Airport On" then
					perform action "AXPress" of menu item "Turn Airport On" of menu 1
					perform action "AXPress"
				end if
				perform action "AXPress" of menu item "Create Network…" of menu 1
			end tell
		end tell
		
		-- Enter information into Create Network Dialog
		tell window 1
			-- Require Password
			click checkbox 1
			
			-- Set to 128 bit WEP
			click pop up button 2
			click menu item 2 of menu 1 of pop up button 2
			
			-- Fill in information
			set value of text field 2 to NetworkPassword
			set value of text field 3 to NetworkPassword
			
			-- Set name last so OK button will be enabled (password field loses focus)
			set value of text field 1 to NetworkName
			
			-- Click OK
			click button 1
		end tell
	end tell
end tell

if BringupScript is not "" then
	tell application "Terminal"
		do script BringupScript
	end tell
end if


[ Reply to This | # ]
Script to create an ad-hoc network to sync iPhone
Authored by: KBoda on Oct 14, '09 04:15:25AM
(*Script for Creating ad-hoc network and turning on internet sharing,
A. Davis http://forums.macrumors.com/showthread.php?t=455614 for internet sharing

Modified by K.Boda on 14th October 2009 for Snow Leopard
First you have to go to the internet sharing pane and edit Airport options to secure your network with a password.
*)



tell application "System Preferences" to set current pane to pane "com.apple.preferences.sharing"
tell application "System Events" to tell process "System Preferences"
click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1 of window "Sharing"
delay 1
if (exists sheet 1 of window "Sharing") then
click button "Start" of sheet 1 of window "Sharing"
end if
end tell
ignoring application responses
tell application "System Preferences" to quit
end ignoring


[ Reply to This | # ]