Questions & Answers

How can I create an Auto Ad Hoc script on Mac OS X Mavericks?

0 votes
533 views
asked May 31, 2015 in Ai Mixers by mwright137 (1,530 points)
Looking to create an ad hoc network on startup.

1 Answer

0 votes
answered May 31, 2015 by mwright137 (1,530 points)
 
Best answer

property NetworkName : "MacMini"  
property NetworkPassword : "thirteenchars"  
property BringupScript : ""  
delay 2 -- wait for menu bar startup     
try  
    do shell script "/usr/sbin/scselect " & NetworkName  
end try  
set success to 0  
tell application "System Events"  
    tell process "SystemUIServer"  
        repeat while (success is 0)  
            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 starts with "Wi-Fi" then exit repeat  
                end repeat  
                tell menu bar item the_menu  
                    perform action "AXPress"  
                    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  
            delay 0.3  
            tell window 1
                click pop up button 2  
                click menu item 4 of menu 1 of pop up button 2  
                delay 0.5  
                set value of text field 3 to NetworkPassword  
                delay 0.5  
                set value of text field 2 to NetworkPassword  
                delay 0.5  
                set value of text field 1 to NetworkName  
                click button 1  
            end tell  
            delay 5  
            if (not (exists window 1)) then  
                set success to 1  
            else  
                set success to 0  
                tell window 1  
                    click button 2  
                end tell  
            end if  
        end repeat  
    end tell  
end tell  
if BringupScript is not "" then  
    tell application "Terminal"  
        do script BringupScript  
    end tell  
end if

...