Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with Applescript

  • 20-04-2019 4:50pm
    #1
    Moderators, Category Moderators, Arts Moderators, Entertainment Moderators, Technology & Internet Moderators Posts: 22,679 CMod ✭✭✭✭


    I'm trying to write a script that will power cycle Wifi if it isn't connected (my Mac refuses to auto reconnect after the router reboots and I've tried everything). I found this simple script online:
    #!/bin/bash
    
    # turn on Wi-Fi if it's turned 'Off'
    if [ $(networksetup -getairportpower en1 | grep -c 'Off') = '1' ]
        then $(networksetup -setairportpower en1 on)
    fi
    
    # cycle Wi-Fi power if missing 'IP address'
    if [ $(networksetup -getinfo Wi-Fi | grep -c 'IP address:') = '1' ]
        then $(networksetup -setairportpower en1 off; network setup -setairportpower en1 on)
    fi
    
    # initiate connection if not connected to the correct network
    if [ $(networksetup -getairportnetwork en1 | grep -c '<networkName>') = 0 ]
        then $(networksetup -setairportnetwork en1 '<networkName>')
    fi
    

    but I can't get it to work. Applescript editor keeps telling me "unknown token" while highlighting the dollar sign.

    Any suggestions?


Comments

  • Registered Users, Registered Users 2 Posts: 5,490 ✭✭✭stefanovich


    I'm trying to write a script that will power cycle Wifi if it isn't connected (my Mac refuses to auto reconnect after the router reboots and I've tried everything). I found this simple script online:
    #!/bin/bash
    
    # turn on Wi-Fi if it's turned 'Off'
    if [ $(networksetup -getairportpower en1 | grep -c 'Off') = '1' ]
        then $(networksetup -setairportpower en1 on)
    fi
    
    # cycle Wi-Fi power if missing 'IP address'
    if [ $(networksetup -getinfo Wi-Fi | grep -c 'IP address:') = '1' ]
        then $(networksetup -setairportpower en1 off; network setup -setairportpower en1 on)
    fi
    
    # initiate connection if not connected to the correct network
    if [ $(networksetup -getairportnetwork en1 | grep -c '<networkName>') = 0 ]
        then $(networksetup -setairportnetwork en1 '<networkName>')
    fi
    

    but I can't get it to work. Applescript editor keeps telling me "unknown token" while highlighting the dollar sign.

    Any suggestions?

    That's a bash script. Not applescript.

    You need to execute it from the terminal.

    Paste that into a file and save it.

    Open terminal and make it executable with
    chmod u+x filename
    
    and the execute with
    ./filename
    


  • Moderators, Category Moderators, Arts Moderators, Entertainment Moderators, Technology & Internet Moderators Posts: 22,679 CMod ✭✭✭✭Sad Professor


    I'm an idiot. Thanks stefanovich.


  • Registered Users, Registered Users 2 Posts: 5,490 ✭✭✭stefanovich


    I'm an idiot. Thanks stefanovich.

    Of course you aren't!


  • Registered Users, Registered Users 2 Posts: 1,023 ✭✭✭Greentree_uk


    try looking at the source of the problem, pretty sure the mac should reconnect. remove it from your preferred networks in system prefs then reconnect and store the password


  • Moderators, Category Moderators, Arts Moderators, Entertainment Moderators, Technology & Internet Moderators Posts: 22,679 CMod ✭✭✭✭Sad Professor


    try looking at the source of the problem, pretty sure the mac should reconnect. remove it from your preferred networks in system prefs then reconnect and store the password

    I have tried that, tried everything. I think it just doesn't like the router, a Virgin Superhub 3. My other Apple computers/devices don't seem to like it much either after the recent firmware updates. I'm planning to get a proper router and switch the Hub to bridge mode.

    It's also an old Mac running El Capitan which probably doesn't help. There's a lot of stuff that just doesn't work anymore. iCloud Drive for example is totally broken. I'll have to replace it soon.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,499 ✭✭✭IamMetaldave


    I had problems a few years ago with a virgin router. I ended up buying an AirPort (it was for extending WiFi to my downstairs area of the apartment). Anyway, I ended making a network on it just for my Apple devices and it’s the best thing ever. It’s stuck to the wall over the staircase and does a great job. Probably a bit much for just one device though :)


  • Moderators, Category Moderators, Arts Moderators, Entertainment Moderators, Technology & Internet Moderators Posts: 22,679 CMod ✭✭✭✭Sad Professor


    Apple have stopped making Airports, which is a shame as I always used them and found them very good.

    If anyone has recommendations for a fairly cheap but reliable and easy to use router that will play nice with both Virgin and Apple devices, I'd welcome them.


  • Registered Users, Registered Users 2 Posts: 3,499 ✭✭✭IamMetaldave


    That’s a shame!! Such a great device.

    I just took a look and there’s a bunch “as new” on eBay.


  • Registered Users, Registered Users 2 Posts: 2,731 ✭✭✭Type 17


    I can confirm that the Virgin Superhub 3 is pure dirt unless bridged and connected to a decent router.

    I'm using a bridged one with a last-generation Airport Extreme and it's a bulletproof combo - I never need to restart them (they do get restarted a few times a year when they're turned off while we're on holidays). They work perfectly with Macs and iOS clients, and with my wife's work PC laptop.

    I'd go with a good used or new/old-stock one if possible.


Advertisement